Javascript/Jquery on click anchor tag addClass to specific LI -


for example, add class 'active' li have class' list-1' when user clicks anchor tag have class 'link-1' , remove class 'active' other lists. same case applies further. suggestion helpful.

<br> <br> <ul class="list-item">     <li class="list-0 active">product one</li>     <li class="list-1">product two</li>     <li class="list-2">product three</li>     <li class="list-3">product four</li> </ul>` <br> <br> ` <div class="pager-list">     <a href="#" class="link-0">1</a>     <a href="#" class="link-1">2</a>     <a href="#" class="link-2">3</a>     <a href="#" class="link-3">4</a> </div> 

try following:

$(".pager-list").find("a").on("click", function(e) {      e.preventdefault();            var value = $(this).data("value");      $(".list-item")          .find(".list-" + value).addclass("active")          .siblings().removeclass("active");  });
<ul class="list-item">      <li class="list-1 active">product one</li>      <li class="list-2">product two</li>      <li class="list-3">product three</li>      <li class="list-4">product four</li>  </ul>  <div class="pager-list">      <a href="#" data-value="1">1</a>      <a href="#" data-value="2">2</a>      <a href="#" data-value="3">3</a>      <a href="#" data-value="4">4</a>  </div>


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -