class method Element.identify

View source on GitHub →

Element.identify(element) → String

Returns element's ID. If element does not have an ID, one is generated, assigned to element, and returned.


Original HTML:

    <li id="apple">apple</li>


  // -> 'apple'
  // -> 'anonymous_element_1'

Resulting HTML:

    <li id="apple">apple</li>
    <li id="anonymous_element_1">orange</li>

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.