JQuery determines whether a property has hasattr

in JQuery coding, we determine if an element has an attribute. JQuery is easy to determine because of the method hasClass $(“input[name=new]”).hasclass (“new”).

, but sometimes we need to determine other attributes, such as a link with rel or no rel. How do you tell?

If there is an attribute $(“#aid”).attr(“rel”) will return the value of rel, or if there is no rel” undefined”

undefined is undefined type, if($(“#aid”).attr(“rel”)==”undefined”) this judgment may not be true.

because of different types. it is recommended to use an if (typeof ($(” # aid “). Attr (” rel “)) = = “undefined”)

Read More: