Attributes
Also, it's worth remembering that DOM elements have attributes other than class, and we can change those too. For this we'll need the following methods:
get the attribute value
set the attribute value
set multiple values
using a callback function
index is the element's position in the selection
value is the current attribute value
remove an attribute
Attributes are everything we see inside the angle brackets when writing HTML code:
<!-- In this example those are href, title, class -->
<a href="#top" title="anchor" class="simple">To Top</a>Attributes you'll encounter most often:
// get the link's URL
$("a").attr("href");
// change the link's URL and title
$("a").attr({
"href": "https://anton.shevchuk.name",
"title": "My Personal Blog"
});
// get the image's alt text
$("img").attr("alt");
// change the image's source
$("img").attr("src", "/images/default.png");Last updated