JQuery Selectors and CSS Slectors in JQuery || Selecting Elements in JQuery

Jquery supports many different ways to select an element  or elements that should meet all but the most awkward requirements.
The following table shows the lists example of other selection methods you might want to use:
Example selection methods:
Select a div with ID of div1
Select all divs with a class of standardDiv.
Select all elements with a class of standardDiv
$(“#div4 #div5”)
Select a div with ID of div5 nested inside a div with id of div4
Select all divs.
$(“.standardDiv”)[0].innerHTML=”hello Naresh”;
Select the first element of a group of divs with class of standardDiv and set innerHTML property to  “hello Naresh”.

CSS Selectors:
In addition to the previous standard selectors, more modern selectors are also available.
The following table shows the lists example of CSS selection methods you might want to use:
CSS Selectors:
First div
Last div
Even-numbered divs
Odd-numbered divs
First child element
Last  child element
Third child element
Any hyperlink starting with the text http://
Any hyperlink ending with .zip
Any hyperlink with the text dotnet in it
$(“input[type=button]”)[0].innerText=”hello Naresh”
Selects first input element of type button and changes innerText property to “hello Naresh”
Gets all check boxes that are checked
All disabled elements
All enabled elements

jQuery also has provides some inbuilt selectors of its own:

jquery selectors:
$(“:button”)[0].innerText=”hello naresh”;
Change inner Text property of first button element.
All elements containing text naresh
All hidden elements
All selected elements
All visible elements
Select all div elements that do not have a class of standardDiv


Post a Comment