This Blog is protected by




Follow by Email


Total Pageviews

Popular Posts

Blog archive

Search This Blog

jQuery | eq() Selector - trickcode

eq() Selector,Jquery Eq Selector,jquery Eq selector example,jquery Eq selector example explanation
Share it:
In this topic, we will learn a jquery Eq selector. jquery Eq selector allows us to select all elements at a specified index.

Jquery Eq Selector:-

jquery Eq selector matches a specific element by counting from the first element to the index value. Suppose that you want to choose the third <p> element on the page. Because the count starts with 0, to select the third <p> element, do the following.

$(‘p:eq(2)’).text(‘Changed this text.’);

jquery Eq selector example:-

In the following HTML example, we will see how to change the font style of <p> elements which is equal to the index value. To accomplish this task we can make use of : eq(index)

<!DOCTYPE html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="//"></script>
            $('p:eq(2)').css('font-family','Comic Sans MS');
<p>Paragraph 1-index[0]</p>
<p>Paragraph 2-index[1]</p>
<p>Paragraph 3-index[2]</p>
<p>Paragraph 4-index[3]</p>
<p>Paragraph 5-index[4]</p>
<p>Paragraph 6-index[5]</p>


Paragraph 1-index[0]
Paragraph 2-index[1]
Paragraph 3-index[2]
Paragraph 4-index[3]
Paragraph 5-index[4]
Paragraph 6-index[5]

jquery Eq selector example explanation:-

$(‘p:eq(2)’).css(‘font-family’,’Comic Sans MS’); This line tells jquery to select <p> element which is equal to the index value. Here the index value is 2, so it will select the third <p> element. So jquery will change the third <p> elements font using CSS method.
Share it:


Post A Comment: