Reputation: 3
I am opening dropdowns in bootstrap by adding show to their elements, which works fine. I am also trying to close other dropdowns that are open, which is what this function does. My function:
function classremove() {
var doesithavetheclass = $('div').hasClass('show');
if (doesithavetheclass == 'true') {
$('div').removeClass('show');
};
return doesithavetheclass;
};
The if
is the part that won't work. Running the code inside the if
works, and defining the variable in the Chrome console works properly, but running the if
inside of the Chrome console doesn't work even if before I defined the variable with dropdowns open with the show class.
Upvotes: 0
Views: 43
Reputation: 15857
The if statement and most of that function is really not needed. You can simplify to only remove the class.
function classremove() {
$('div').removeClass('show');
};
Upvotes: 1