0

I have these buttons

<button id="btn1" type="button" class="btn btn-default btn-sm margin-left-1">
    <span class="glyphicon glyphicon-chevron-down"></span>
</button>

<button id="btn2" type="button" class="btn btn-default btn-sm margin-left-1">
    <span class="glyphicon glyphicon-chevron-down"></span>
</button>

...etc

And I want to remove the class glyphicon-chevron-down and add glyphicon-chevron-up after a click on that button.. it's twitter bootstrap collapsing but I want to have a button with an icon there :-)
The id of the record can be put in the button tag or in the span tag, does not matter, is there any way I can check applied CSS?
For example, ${#element}.existCSS?('glyphicon-chevron-down') ?

4
  • 2
    $("#element").hasClass('glyphicon-chevron-down') Commented Sep 15, 2013 at 17:09
  • 2
    api.jquery.com/toggleClass Commented Sep 15, 2013 at 17:11
  • thanks DevIshOne thats it. Commented Sep 15, 2013 at 17:51
  • @devo: while editing, please don't just add tags - try to fix as much as possible. Commented Sep 24, 2013 at 9:18

2 Answers 2

1

Try:

if( $(<#element>).hasClass("glyphicon-chevron-down") ) {
 //Your code
}
Sign up to request clarification or add additional context in comments.

1 Comment

That is just a placehloder for the element selector in the pseudo code.
0

You can try this:

$('.btn-default').click(function() { $(this).find('.glyphicon-chevron-down').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
});

look at this - http://jsfiddle.net/9NDyL/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.