Jquery

Add and remove html attributes using jquery

Setting value of HTML attribute

If you want to add an attribute to some element you can use the attr(attributeNameFor example:


$('a').attr('title''Click me');

This example will add mouseover text "Click me" to all links on the page.

The same function is used to change attributes' values.

Removing attribute

To remove an attribute from an element you can use the function .removeAttr(attributeName).

For example:

$('#home').removeAttr('title');


This will remove title attribute from the element with ID home