identify
1.6

identify(element) -> id

returns element’s id attribute if it exists, or sets and returns a unique, auto-generated id.

Examples

Original HTML


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

JavaScript


  $('apple').identify();
  // -> 'apple'

  $('apple').next().identify();
  // -> 'anonymous_element_1'

resulting HTML


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