1

I create a click event but that event affects both dropdown i want do one by one, also i would like when I click in the next dropbox the first icon back to place, does not matter if i click in the first or second always puting back the icon that is my html and jquery : http://jsfiddle.net/rtu1tzep/

html:

    <div class="body-title">
        title
    </div>

    <div class="form-group">
        <div class="col-md-16">
      <button type="button" class="btn btn-lg dropdown-toggle btn_body" data-toggle="dropdown" aria-expanded="false">
      <span id="users_label">users</span><i class="glyphicon glyphicon-asterisk"></i></button>
        </div>
    </div>

    <div class="form-group">
       <div class="col-md-16">
        <button type="button" class="btn btn-lg dropdown-toggle btn_body" data-toggle="dropdown">
     <span id="clients_label">clients</span>
    <i class="glyphicon glyphicon-asterisk"></i>

             </div>
        </div>

</div>

jquery:

  $( ".btn_body" ).click(function(){
    $('i').removeClass('glyphicon-asterisk');
    $('i').addClass('glyphicon-star');
  });
raduken
  • 2,091
  • 16
  • 67
  • 105

4 Answers4

1

Change your Jquery.

$(".btn_body").click(function () {
        $('.btn_body').find('i').addClass('glyphicon-asterisk');
        $('.btn_body').find('i').removeClass('glyphicon-star').css('color', '');
        $(this).find('i').removeClass('glyphicon-asterisk');
        $(this).find('i').addClass('glyphicon-star').css('color', 'red');
    });
Lalji Tadhani
  • 14,041
  • 3
  • 23
  • 40
1

This is what you want I think.

$( ".btn_body" ).click(function(){
  $('i').removeClass('glyphicon-star');
  $('i').addClass('glyphicon-asterisk');
  $(this).children('i').removeClass('glyphicon-asterisk');
  $(this).children('i').addClass('glyphicon-star');
});
Elie Faës
  • 3,215
  • 1
  • 25
  • 41
1

Demo

  $(".btn_body").click(function () {
      $(this).find('i').toggleClass('glyphicon-asterisk glyphicon-star');
      if ($(".btn_body").not(this).find("i").hasClass("glyphicon-star")) {
          $(".btn_body").not(this).find("i").toggleClass('glyphicon-asterisk glyphicon-star');
      }
  });
1

Try this

$( ".btn_body" ).click(function(){
$('i').removeClass('glyphicon-star');
$('i').addClass('glyphicon-asterisk');
$(this).children('i').removeClass('glyphicon-asterisk');
$(this).children('i').addClass('glyphicon-star');
});
Tal
  • 1,091
  • 12
  • 25