lb.base.dom

DOM (Document Object Model) Adapter Module for Base Library

Authors

Copyright

Eric Bréchemier © 2011, Some Rights Reserved Legal-Box SAS © 2010-2011, All Rights Reserved

License

BSD License http://creativecommons.org/licenses/BSD/

Version

2011-08-14

Summary
lb.base.domDOM (Document Object Model) Adapter Module for Base Library
Functions
$(id): DOM ElementAn alias for document.getElementById(id).
hasAttribute(element, attributeName): booleanCheck whether an attribute with given name has been specified on given element.
Constants
ELEMENT_NODEThe nodeType value of element nodes: 1.
ATTRIBUTE_NODEThe nodeType value of attribute nodes: 2.
TEXT_NODEThe nodeType value of text nodes: 3.

Functions

$(id): DOM Element

An alias for document.getElementById(id).

Parameter

idstring, the identifier of an HTML element

Returns

DOM Element, the element with given id, if present in the document, null otherwise

Note

”Behavior is not defined if more than one element has this ID”

DOM Level 2 Core http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBId

hasAttribute(element, attributeName): boolean

Check whether an attribute with given name has been specified on given element.

The native hasAttribute() function is used when available.  When missing, it is emulated by checking DOM level 2 property ‘specified’ of the attribute node.

Parameters

elementDOM Element, the element to check for given attribute
attributeNamestring, an attribute name

Returns

  • true if the attribute has been defined on the element,
  • false otherwise

Note

When the behavior is emulated, in IE, the attribute may not have been defined in the original document or through JavaScript, but may be an optional attribute set to its default value.

Source

Adapted from bezen.dom.hasAttribute() in bezen.org JavaScript library, CC-BY: Eric Bréchemier - http://bezen.org/javascript/

References

hasAttributeintroduced in DOM Level 2 http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElHasAttr
specifiedInterface Attr http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-637646024

Constants

ELEMENT_NODE

The nodeType value of element nodes: 1.

ATTRIBUTE_NODE

The nodeType value of attribute nodes: 2.

TEXT_NODE

The nodeType value of text nodes: 3.

Close