Aug 11, 2007

Some handy feature in jQuery

attr( key, fn )

Sets title attribute from src attribute.

$("img").attr("title", function() { return this.src });

 

toggleClass( class )

$("p").toggleClass("selected")

 

Before

Hello

Hello Again

 

After

[

Hello

,

Hello Again

]

 

 

get()

return an array that contains in jQuery object

 

get( num )

return an

 

html(), text() and val()

html(val), text(val) and val(val)

end()

Revert the most recent 'destructive' operation, changing the set of matched elements to its previous state (right before the destructive operation).

If there was no destructive operation before, an empty set is returned.

A 'destructive' operation is any operation that changes the set of matched jQuery elements. These functions are: add, children, clone, filter, find, not, next, parent, parents, prev and siblings.