Categories

Attribute Has Selector [attribute]

Categories: Attribute

jQuery('[attribute]')

Description: Selects elements that have the specified attribute, with any value.

  • jQuery('[attribute]')

    version added: 1.0

    attribute   An attribute name.

  • Bind a single click that adds the div id to its text.

    HTML:
    <div>no id</div>
      <div id="hey">with id</div>
    
      <div id="there">has an id</div>
      <div>nope</div>
    Code:
    
    
        $('div[id]').one('click', function(){
          var idString = $(this).text() + ' = ' + $(this).attr('id');
          $(this).text(idString);
        });