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>

Updated on 14-Feb-2020 10:40:25