Has Attribute [attr] JQ Home  <<  Selectors  <<  Has Attribute [attr]

Has attribute selector.

Shorthand version $('[attr]')

Description

The [attr] selector, selects all elements that have the specified attribute name.

Syntax

Signature Description
jQuery('[attr]')Attribute match

Parameters

Parameter Description
attrThe attribute name.

Return

N/A.

Has Attribute [attr] Example Selectors  <<  Top

Selects all elements that have the specified attribute name.

The following example will select all 'href' attributes on the page and change their color to purple (all links on the page apart from those in tables).




$(function(){
  $('#btn12').on('click', function() {
    $([href]).css('color', 'purple');
  });
}); 


Press the button below to action the above code:

Related Tutorials

jQuery Basic Tutorials - Lesson 3 - CSS Selectors