Selector: Gets all p elements on page (to access all elements of one type).

So now let us look at one another powerful jQuery selector. Suppose you want to choose all "<p>" elements of the page and then change its css property(for example-the text color to red.)

The syntax of selecting all <p> tags or elements of the page in jQuery is as follows:

$("p") -it will select all p elements of the page.

All DOM elements can be referred in the same way(for example- all tr elements can be selected as $("tr") , etc.)

To clear its usage, let us look at an example-

<!– code starts –>

<p> hello how are you all</p>
see the effect
<p> its really amazing </p>

<script type=’text/javascript’>
$("p").prepend("*****");

</script>

<!–code ends–>

When you will look at the output, you will see something like the following:

***** hello how are you all
see the effect
***** its really amazing

So i think that now its clear that this selector will choose all p elements that are available on the page. Similarly you can refer any element of the page, like all <u> elements, all <a> elements, etc.

Leave a Reply

Your email address will not be published.