When a single parameter is passed to the .attr() function it returns the value of passed attribute on the selected element.
Syntax:
$([selector]).attr([attribute name]);Example:
- HTML:
<a href="/home">Home</a>
- jQuery:
$('a').attr('href');
Output: /homejQuery offers .data() function in order to deal with data attributes. .data function returns the value of the data attribute on the selected element.
Syntax:
$([selector]).data([attribute name]);Example:
Html:
<article data-column="69"></article>
jQuery:
$("article").data("column");
Output: 69