How to get attribute of an element when using the 'click' event in jQuery?

jQueryWeb DevelopmentFront End Technology

To get attribute of an element, use the attr() method in jQuery. You can try to run the following code to get attribute of an element using the ‘click’ event −


Live Demo

<!DOCTYPE html>
<script src=""></script>
        alert("Width of image: " + $("img").attr("width"));

<img src="/videotutorials/images/coding_ground_home.jpg" alt="Coding Ground" width="284" height="280"><br>

<button>Get Width</button>

Published on 19-Dec-2017 19:29:17