Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  133] [ 3]  / answers: 1 / hits: 8505  / 10 Years ago, thu, june 12, 2014, 12:00:00

I have a Bootstrap webpage set up which displays a collapsible table. Each table row has a button which has a glyphicon-chevron-down icon. When a user clicks on this button, that icon needs to change to glyphicon chevron-up. I have tried doing this a few different ways to no avail.



Current set up is:



<script >
function toggleChevron(button) {
if (button.find('span').hasClass('glyphicon-chevron-down')) {
button.find('span').className = glyphicon glyphicon-chevron-up;
}
if (button.find('span').hasClass('glyphicon-chevron-up')) {
button.find('span').className = glyphicon glyphicon-chevron-down;
}
}
</script>

<button type=button onclick=toggleChevron(this) class=btn btn-default>
<span class=glyphicon glyphicon-chevron-down></span>
</button>


JSFiddle


More From » html

 Answers
5

This works:



toggleChevron = function(button) {
$(button).find('span').toggleClass('glyphicon-chevron-down glyphicon-chevron-up');
}


The main issue is that you are passing this, which isn't a jQuery object, so you need to wrap button in the jQuery function $(button)



http://jsfiddle.net/V9LSS/4/


[#44606] Thursday, June 12, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
annalise

Total Points: 210
Total Questions: 94
Total Answers: 102

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
annalise questions
Mon, May 24, 21, 00:00, 3 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sat, Sep 12, 20, 00:00, 4 Years ago
Tue, Jul 28, 20, 00:00, 4 Years ago
;