AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

[jQuery] :Even Selector - Trickcode

By pushpam abhishek
Listen to this article


: Even is the jQuery selector that selects the first, third, fifth (and so on) element of a page that is of the same type or that have the same class.

Example of what you get using the jQuery: even selector


In this example, when the button is clicked, the first, third, and fifth block will be selected and get their content filled with a background color.
Line 1
Line 2
Line 3
Line 4
Line 5


Step 1
You need to specify elements that are the same type or that have the same class.

<div class="line">Line 1</div>
<div class="line">Line 2</div>
<div class="line">Line 3</div>
<div class="line">Line 4</div>
<div class="line">Line 5</div>
<button>Click me</button>
Step 2
Finally, the following jquery indicates that when the button is clicked, the first, third, and fifth lines will get a background color.


$('button').click(function(){
	$('.line:even').css('background-color', '#bbbbff');
});

Example of: even with table rows


Row 1
Row 2
Row 3
Row 4
Row 5


<table border="1">
	<tr><td>Row 1</td></tr>
	<tr><td>Row 2</td></tr>
	<tr><td>Row 3</td></tr>
	<tr><td>Row 4</td></tr>
	<tr><td>Row 5</td></tr>
</table>

<script>
$('tr:even').css('background-color', '#bbbbff');
</script>

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments