728x90
SMALL
#jquery
#:odd
:odd
:odd is a selector that selects odd-indexed elements.
grammar
$( ':odd' )
for example
$( 'p:odd' )
Select p elements that are odd indices. One thing to note is that the indices start at zero.
example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery</title>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$( document ).ready( function() {
$( 'li:odd' ).css( 'color', 'red' );
} );
</script>
</head>
<body>
<ul>
<li>0. Lorem</li>
<li>1. Ipsum</li>
<li>2. Dolor</li>
<li>3. Sit</li>
</ul>
</body>
</html>
Selects li elements with odd indices and replaces the text color with red.
728x90
LIST