javascript - Change link color on click Jquery -


i code in html / css , jquery :

$('.myfilters li').click(function() {      $(".category").hide();      var v = $(this).text()[0]      $('.title li').hide().filter(function() {          return $(this).text().touppercase()[0] == v;          $(".category:first").show();      }).show().first().find('a[data-toggle]:first').trigger('click');  })    $("a[data-toggle]").on("click", function(e) {      e.preventdefault(); // prevent navigating      var selector = $(this).data("toggle"); // corresponding element      $(".category").hide();      $(selector).show();  });      $('.myfilters li:first').trigger('click');  //$('.title li:first a[data-toggle]').trigger('click');
.myfilters,  .title {  	margin: 0;  	padding: 0;  }    .myfilters {    display:inline-block;  	margin-right: 10px;  	margin-bottom: 15px;  }    .myfilters li {    display:inline-block;  	margin-right: 10px;  }    .myfilters li {  	font-size: 22px;  	font-style: normal !important;  	font-weight: bold;    text-decoration: none;    color: black;  }    #menu-navigation > li:first-child{     color:red;  }    .title {  	margin-bottom: 30px;  }    .title li {  	display: inline-block;  	list-style-type: none;  	padding: 15px;  	background-color: white;  	border: 1px solid #d6205c;  	color: white;      margin-right: 15px;      margin-bottom: 10px;      padding: 0;  }    .title li {      display: block !important;      color: #d6205c;      padding: 5px;      font-style: normal !important;      margin: 0 !important;  }      .category {  	margin-bottom: 25px;  	margin-top: 40px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <ul class="myfilters">      <li data-type="a"><a href="#">a</a></li>      <li data-type="b"><a href="#">b</a></li>      <li data-type="c"><a href="#">c</a></li>  </ul>  <div class="filter">      <ul class="title">          <li><a href="#" data-toggle="#assurance">assurance</a></li>          <li><a href="#" data-toggle="#couverture">couverture</a></li>          <li><a href="#" data-toggle="#banque">banque</a></li>          <li><a href="#" data-toggle="#alimentation">alimentation</a></li>      </ul>      <div id="assurance" class="category">          <ul>              <li>groupama</li>          </ul>      </div>      <div id="couverture" class="category">          <ul>              <li>try !</li>          </ul>      </div>      <div id="alimentation" class="category">          <ul>              <li>an example</li>          </ul>      </div>  </div>

when click on letter, categories appears , companies.

what want when click on letter, letter changes color.

and same categories, when click on category, background changes.

thanks !

try fiddle

$('.myfilters li').click(function() {     $('.myfilters li').find('a').removeclass('red');     $(this).find('a').addclass('red');     $(".category").hide();     var v = $(this).text()[0]     $('.title li').hide().filter(function() {         return $(this).text().touppercase()[0] == v;         $(".category:first").show();     }).show().first().find('a[data-toggle]:first').trigger('click'); })  $("a[data-toggle]").on("click", function(e) {     e.preventdefault(); // prevent navigating     var selector = $(this).data("toggle"); // corresponding element     $(".category").hide();     $(selector).show(); });   $('.myfilters li:first').trigger('click'); //$('.title li:first a[data-toggle]').trigger('click'); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -