Home > Article > Web Front-end > How to determine if there is a certain attribute in jquery
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.
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!