How to determine if there is a certain attribute in jquery

藏色散人
Release: 2022-12-30 11:13:52
Original
4611 people have browsed it

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('属性存在') }
Copy after login

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!

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!