Attributes API

attr.set()

Sets the attribute values for the matched DOM elements.

  • Accepts either two string arguments or a single object.
Example:
$('body').attr.set('data-name', 'book');
// Sets the attribute 'data-name="book"' on the <body> element.

$('body').attr.set('data-bookName', 'cat');
// Sets the attribute 'data-bookName="cat"' on the <body> element.

$('div ?').attr.set('data-book-name', 'cat');
// Sets the attribute 'data-book-name="cat"' on all <div> elements.

$('body').attr.set({'data-name': 'book', class: 'main'});
// Sets the attribute 'data-name="book"' and 'class="main"' on the <body> element.