How to judge whether jquery class exists: first create an html code example; then judge through if judgment and hasClass function, statements such as "if($("#div").hasClass('on') ){$(this).css("display"..)".
The operating environment of this tutorial: Windows 7 system, jquery version 1.10.0. This method is suitable for all brands of computers.
Recommended: "jquery video tutorial"
jquery determines whether a tag has a certain class
if is mainly used here The judgment is made with the hasClass() function. The following is the code:
html code:
如果有名为on的class则隐藏这个div
js code:
$(function(){ if($("#div").hasClass('on')){ $(this).css("display","none"); } });
This is often used to add a class to a specific tag, and then Achieve the effect of clicking to hide a div, such as a filter button. After clicking on an option, the entire similar filter box is hidden.
For more programming-related knowledge, please visit:Programming Teaching! !
The above is the detailed content of How to determine whether jquery class exists. For more information, please follow other related articles on the PHP Chinese website!