hasAtrr()

The hasAttr method checks if an element have specific attributes.


Returns

  • true if all specified attributes exist.

  • false otherwise.

Usage

For Single Elements

$('.button').hasAttr('id'); // Checks if the element has an 'id' attribute
$('.link').hasAttr('href', 'target'); // Checks for multiple attributes

For Collections

$('img*').hasAttr('src'); // Checks if all <img> elements have a 'src' attribute
$('input').hasAttr('type', 'name'); // Checks if all <input> elements have both attributes

Last updated