Sunday 30 November 2008

JQuery Predicates - Attribute ends with

Add following click handlers to page using console in FireBug
  • $("#lnkRedAttributeEndsWith").click(showRedEndsWith);
  • $("#lnkYellowAttributeEndsWith").click(showYellowEndsWith);
To find an element with an id of 'HelloGoodbyeAttributeEndsWith'
click me yellow
click me red

The click me red also finds the two links as their ids match the predicate. The click me yellow is specifically looking for div elements therefore the two links are not turned yellow.


JQuery Predicate, attribute Ends With
$("[id$='teEndsWith']").removeClass("YellowAttributeEndsWith").addClass("RedAttributeEndsWith"); 

or

$("div[id$='teEndsWith']").removeClass("RedAttributeEndsWith").addClass("YellowAttributeEndsWith"); 

No comments: