I cannot get the value of attribute alt of img tag
Following is for Getting the value of attribute alt of img tag
<html>
<head>
<script>
$('img').click(function () {
var alt = $(this).attr("alt")
alert(alt);
});
</script>
</head>
<img src="white.png" width="25px" height="25px" alt="1" id="star1" onmouseover="starOverOne()" onmouseout="starOutOne()"/>
Here Nothing displayed in alertbox..Can you help me??
The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).
Chrome™ browser: point to the image with your mouse, right-click and choose Inspect from the quick menu (or use Ctrl-Shift-I on keyboard). A new pane will open at the right of your screen with the HTML code highlighted for that element. You can then view the alt text and other attributes for the image.
So yes, three images can all have the same alt text, but only if all three images are identical. If the images aren't identical, the alt texts should include a description of their differences.
The <img> alt attribute is used to specify the alternate text for an image. It is useful when the image not displayed. It is used to give alternative information for an image. Attribute Values: It contains single value text which specifies the alternative text for an image.
Remember to wrap your code inside $(document).ready(function() {...});
and include your jQuery library. Try to follow this basic HTML structure:
<html>
<head>
</head>
<body>
<img src="white.png" width="25px" height="25px" alt="1" id="star1" onmouseover="starOverOne()" onmouseout="starOutOne()"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('img').click(function () {
var alt = $(this).attr("alt")
alert(alt);
});
});
</script>
</body>
</html>
Demo: http://jsfiddle.net/aHRN7/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With