How to determine whether jquery class exists

藏色散人
Release: 2020-12-23 17:08:58
Original
2229 people have browsed it

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"..)".

How to determine whether jquery class exists

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
Copy after login

js code:

$(function(){ if($("#div").hasClass('on')){ $(this).css("display","none"); } });
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!