Home  >  Article  >  Web Front-end  >  How to determine if there is a certain attribute in jquery

How to determine if there is a certain attribute in jquery

藏色散人
藏色散人Original
2021-02-05 10:07:074642browse

How jquery determines whether there is a certain attribute: First create a code sample file; then use the "$("input[name=new]").hasClass("new")" method in JQuery coding Just determine whether there is a certain attribute.

How to determine if there is a certain attribute in jquery

The operating environment of this article: Windows7 system, jquery1.2.6, Dell G3 computer.

jquery determines whether a certain attribute is included?

In JQuery coding, we will determine whether an element has a certain attribute, such as whether it contains a class="new" style. JQuery judgment is very simple, because there is hasClass method $("input[name=new]").hasClass("new") to judge.

But sometimes we need to determine other attributes. For example, some a links contain the rel attribute, and some do not. How to judge at this time?

There is no ready-made method at this time. If there is an attribute $("#aid").attr("rel"), it will return the value of rel. If there is no rel attribute, it will return "undefined"

undefined is the undefined type, use if( $("#aid").attr("rel") == undefined) Just make the judgment.

if($('#app').attr('checked') == undefined ){
    alert('属性存在')
}

Recommended: "jquery video tutorial"

The above is the detailed content of How to determine if there is a certain attribute in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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