Saturday, August 24, 2013

Identifying the elements by attribute values in Jquery

$(‘element[attribute=”value”]’): Selects all elements that have the specified attribute with a value exactly equal to a specified value.
Ex:  $('span[id="spnTest1"]').css('background-color', 'red');

$(‘element[attribute^=”value”]’): Selects all elements that have the specified attribute with a value beginning with specified value. The comparison is case sensitive.
Ex: $('span[id^="span"]').css('background-color', 'blue');

$(‘element[attribute$=”value”]’): Selects all elements that have the specified attribute with a value ending with specified value. The comparison is case sensitive.
Ex: $('span[id$="test3"]').css('background-color', 'yellow');

$(‘element[attribute*=”value”]’): Selects all elements that have the specified attribute contains sub string of specified value. The comparison is case sensitive.
EX: $('span[id*="test"]').css('background-color', 'green');

No comments:

Post a Comment