简体   繁体   中英

Is it possible with Jquery to change a class after every 5th time it is displayed on a page?

Is it possible with Jquery to change a class after every 5 times it is displayed on a page?

For example, I'm working with an api script that outputs several contact records. The API does not give me access to the area of the output of the records, but it does give me a <div class="style-close"></div> at the end of each set of records.

A record looks like this:

<div class="contact"> 
 <p>content </p>
<div class="contact-name><p>content</p></div>
<div class="contact-address><p>content</p></div>
</div>
<div class="style-close"></div>

Can use :nth-of-type-selector

$('.style-close:nth-of-type(5n)').doSomething()

:nth-of-type() Docs

Note: Can also do same in css without script

https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM