I am facing a problem in a Jquery code. Please help me to fix this problem.
HTML Code for showing images:
<body>
<div class="info_image">image1</div>
<div class="info_image">image2</div>
<div class="info_image">image3</div>
The image links with id:
<div class="reference">
<p><img id="image1" src="brush-seller.jpg"/></p>
<p><img id="image2" src="Pest-seller.jpg"/></p>
<p><img id="image3" src="pick-seller.jpg"/></p>
</body>
Now the problem is with JavaScript. I have to use .attr(‘src’,value) tag to use the image id as source and show that image in first 3 div. So far I found a code which didn’t work:
.attr('src','image/'+info_elem.find('.info_image').html())
Please help me to fix this jquery code.
Use
.each()to iterate over the Div’s . Fetch the htmlAnd use
.css()to set the corresponding background imageBetter to use HTML5 data attribute to store the image ID instead of the html as you might need to handle the cases of empty spaces or other characters…
Javascript
This will be lot cleaner