Posts

Showing posts with the label hidden

Check if the element is hidden or not, but “else” is not working

Check if the element is hidden or not, but “else” is not working I have a block, that when user clicks on it, some information appears (they are hidden by default). I want, when user clicks again on that block, the information will be closed again. I use "if", that element has "hidden" class, do something. Those hidden classes should be removed after this, so it means if I write an "else" after if, it should work, but it is not working. For the test I put an alert on else, but nothing happens, when I click on the block again, when the information is open. if ($(".container-info").find(".content-holder").hasClass("hidden")) { $(e.target).closest(".container-info").find(".hidden").removeClass("hidden"); } else { alert("Im Working!"); } That's not how else works. It will do the test once and then choose which path to take. If you change something inside t...