How to get html attribute's value in jquery?

Last updated 4 years, 7 months ago | 1393 views 75     5

Tags:- JQuery

Jquery | attr | Get HTML attribute's value

You can get the value of an attribute for the first element in the set of matched elements using the .attr() function.


Return the value of an attribute:

<!DOCTYPE html>
<script src=""></script>
    var image_height = $("img").attr("height");

<img src="image.jpg" alt="Pulpit Rock" width="284" height="213"><br>

<button>Get the attribute height value</button>


Note: if there is a number of matched elements and To get the value for each element individually, use a looping construct such as jQuery's .each() or .map() method.