jQuery Selector :nth-of-type() with formula

Description

jQuery Selector :nth-of-type() with formula

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("p:nth-of-type(3n+2)").css("background-color", "yellow");
});/*from   w  w w  .ja  va  2  s . co m*/
</script>
</head>
<body>

<p>The p:nth-child(3n+2) selects each 3rd paragraph, starting at the 2nd paragraph.

<div style="border:1px solid;">
  <span>This is a span element.</span>
  <p>The first paragraph.</p>
  <p>The second paragraph.</p>
  <p>The third paragraph.</p>
  <p>The fourth paragraph.</p>
  <p>The fifth paragraph.</p>
  <p>The sixth paragraph.</p>
  <p>The seventh paragraph.</p>
  <p>The eight paragraph.</p>
</div><br>

</body>
</html>



PreviousNext

Related