jQuery Apps

HTML Elements, Attributes, and Positions on jQuery

This post is also available in: Romanian

jQuery Apps

Recently I went into studying the jQuery scripts and I believe that these codes can be a start for anyone interested. Following are some order selectors and examples of their use with elements in the preceding code:


radio: –  Selects all elements with the type attribute set to radio. The following code returns the value 1 in an alert box:

alert( $(‘:radio’).length);

checkbox: – Selects all elements with type attribute set to radio. The following code sets the checked attribute to true for all check boxes:

$(‘:checkbox’).attr({checked:’true’});

[attribute]:  – Selects all elements with a specific attribute. The following code displays the number of <img> elements with a height attribute:

alert( $(‘img[height]’).length);

[attribute=value]:  – Selects all elements with a particular attribute set to a specific value. The following code displays the number of elements with a class attribute set to myclass:

alert( $(‘[class=myclass]’).length);

[attribute!=value]: –  Selects all elements with a particular attribute not set to a specific value. The following code displays the number of elements with a class attribute that isn’t myclass. Elements with no class attribute are ignored:

alert( $(‘[class!=myclass]’).length);

 

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload CAPTCHA.