What is the correct syntax for this?

dreamhack

New Member
I'm trying to fade in images on top of an existing image when I mouse over them, without re-writing the same function for each image.Currently I have:\[code\]<script type="text/javascript"> $(document).ready(function() { $('.image').mouseenter(function() { //fade in hover image $(this.getAttribute("name")).fadeIn(500); }); $('.hoverimage').mouseout(function() { //fade out hover image $(this).fadeOut(500); }); });</script>......<!--base images--><img src="http://stackoverflow.com/questions/15648945/image1.png" class="image" name="hoverimage1"><img src="http://stackoverflow.com/questions/15648945/image2.png" class="image" name="hoverimage2"><img src="http://stackoverflow.com/questions/15648945/image3.png" class="image" name="hoverimage3"><!--image to appear when hovering over--><img src="http://stackoverflow.com/questions/15648945/image1_glow.png" class="hoverimage" id="hoverimage1"><img src="http://stackoverflow.com/questions/15648945/image2_glow.png" class="hoverimage" id="hoverimage2"><img src="http://stackoverflow.com/questions/15648945/image3_glow.png" class="hoverimage" id="hoverimage3">\[/code\]Assume that CSS is already there so that the hover image is placed on top of the base image. What my code tries to do is:
  • When mouse enters div of "image1.png", it will get the name attribute "hoverimage1"
  • Then it fades in an element with the ID "hoverimage1" by essentially executing $('#hoverimage1").fadeIn(500);
But the problem is the name attribute doesn't have "#", and I don't want to write "name="#hoverimage1" cause that's confusing for IDs. Right now my function executes $('hoverimage1").fadeIn(500); which is not correct syntax.Can someone help me with this? Is it possible to append a "#" to the "$(this.getAttribute())" or something?
 
Back
Top