How to get attribute value of image tag using jQuery?
Are you new user to jQuery? Then this code snippet will be useful for you. You can use this to find different attribute values of different tags. Make sure "jquery-1.4.1.js" file exists in scripts folder of your .Net application else you can download it.
Add html page in your .Net application and put following lines of code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Find attribute value of image tag using jQuery.</title>
<script src ="Scripts/jquery-1.4.1.js" type ="text/javascript">
</script>
<script type ="text/javascript">
$(document).ready(function () {
$("button").click(function () {
alert($('#myimage').attr('src'));
});
});
</script>
</head>
<body>
<input type="image" src ="circle.png" id="myimage"/>
<button id="mybutton" value = "Submit">Submit</button>
</body>
</html>
We have taken image and button for demo purpose. You can take any input types and pass attribute values for which you need to display alert and check.
Add image source to your application. In this example, whenever user clicks on submit button, user will find the source attribute value of image as alert. As we have used src = circle.png as source attribute for image,we will be able to see it in alert.