Monday, September 22, 2008

Changing HTML tag attributes with Javascript

Just in case I forget all about this and I'm sure someone may find it useful.

It's probably commonplace to access certain attributes like style and class but what if you want to set your own attributes on an html tag.

On ExtJS, you can add a quicktip to any html element by simpley adding "ext:qtip" attribute like so.

<div id='mydiv' ext:qtip='Empty div'>

Now what if you want to add or dynamically change the qtip on that element. Here's how I did it.

var newtip = document.createAttribute('ext:qtip');
newtip.value = "It's not empty anymore";
document.getElementById('mydifv).attributes.setNamedItem(newtip);

1 comment: