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.

How to get attribute value of image tag using jQuery?
Add html page in your .Net application and put following lines of code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<title>Find attribute value of image tag using jQuery.</title>

<script src ="Scripts/jquery-1.4.1.js" type ="text/javascript">
<script type ="text/javascript">
$(document).ready(function () {
$("button").click(function () {
<input type="image" src ="circle.png" id="myimage"/>
<button id="mybutton" value = "Submit">Submit</button>

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.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: