?
Solved

please see what is wrong with my jquery code

Posted on 2012-04-07
1
Medium Priority
?
194 Views
Last Modified: 2012-04-22
Hi,

I would have expected the code below to have changed the alt tags on the imgs however when I use firebug to look at the code I see that the alts remain unchaged.


<html>
      <head>
            <title>This is a test</title>
            <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
            <script type="text/javascript">
                  $('img').each(function(n) {
                        this.alt='This is an image['+n+'] with an id of '+this.id;
                  });
                  
            </script>
            </head>
            <body>
                  <img id="myImage" src="image.gif" alt="An image" class="someClass" title="This is an image" />
                  <img id="myImage2" src="image2.gif" alt="An image2" class="someClass2" title="This is an image2" />
            </body>
</html>
0
Comment
Question by:jecommera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 37819610
Here you go.
<script type="text/javascript">
	$(document).ready(function() {
		$('img').each(function(n) {
			$(this).attr('alt', 'This is an image['+n+'] with an id of '+this.id);
		});
	});
</script>

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question