8 | ||||
Returns whether the current element has any attributes specified or not.
Note: The hasAttributes method is supported in Internet Explorer from version 8.
In earlier versions of Internet Explorer, use the specified property of the attribute objects contained by the attributes collection of the current element to detect the specified attributes.
For further details, see Example 1 below.You can find the related objects in the Supported by objects section below.
Boolean. One of the following values:
No attribute is specified for the current element. | |
At least one attribute is specified for the current element. |
This example illustrates the use of the hasAttributes method:
|
||||
<head> <script type="text/javascript"> function HasAttr (button) { var hasAttrs = false; if (button.hasAttributes) { hasAttrs = button.hasAttributes (); } else { // Internet Explorer before version 8 var attrs = button.attributes; for (var i = 0; i < attrs.length; i++) { if (attrs[i].specified) { hasAttrs = true; break; } } } if (hasAttrs) { alert ("At least one attribute is specified for the button."); } else { alert ("No attribute is specified for the button."); } } </script> </head> <body> <button onclick="HasAttr (this)">Does it have any attributes or not?</button> </body> |
||||
|
||||
Did you find this example helpful?
|
CommentNode, doctype, document, DocumentFragment, TextNode, XMLDocument
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
User Contributed Comments