最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - If user has clicked link add class and store using PHPWordpress

programmeradmin2浏览0评论

I have multiple divs on my website that are clickable. I simply want that when the user clicks this div, a class is then added so they know they have viewed this.

For example, we could have a list of 10 links on the site. Once they click a link, the 'viewed' class would be added, to set a background colour to green.

I know the below is a simply way to do this in jQuery, but if someone could please help with storing this in PHP it would help so much, I am quite stuck on this!

  <script src=".3.1/jquery.min.js"></script>
  <script src=".5.0.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
  <div class="clickable-links">
    <div class="link1">Lnk 1</div>
    <div class="link2">Lnk 2</div>
    <div class="link3">Lnk 3</div>
  </div>

  .viewed {
    background: red;
  }

  $(function() {
    $('.clickable-links > div').click(function() {
      $(this).addClass("viewed");
    });
  });
发布评论

评论列表(0)

  1. 暂无评论