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');
Fetching data
attributes:
jQuery 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="3"></article>
jQuery:
$("article").data("column")
Note:
jQuery's data() method will give you access to data-* attributes, BUT, it clobbers the case of the attribute name. Reference