[jQuery] :Even Selector - Trickcode

:Even Selector, jQuery selector ,Example of what you get using the jQuery: even selector
Share it:


: 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 it:

jQuery

Post A Comment:

0 comments: