Solved

please see what is wrong with my jquery code

Posted on 2012-04-07
1
193 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 500 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

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)

691 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