0

Actually i wanted to generate images dynamically with hyperlinks through jquery which is appended in <div id='data'></div>.

Through this code now i am able to create images but i am not getting idea to provide hyperlinks to the generated images. Just for the sake of simplicity, here I have inserted only a single image.

<html>
<head>
<script src="jquery.min.js" type='text/javascript'></script>
<script type='text/javascript'>
$('#gallery h3').click(function(){{
$('<img></img>')
.attr('src', 'photo.jpg')
.hide()
.load(function() {
    $(this).fadeIn(4000);
    })
.appendTo($('#data'));
  }
</script>
</head>
<body>
<div id='gallery'>
<h3 id='gdata'><a href='#'>Browsers</a></h3>
<div id='data'></div>
</div>
</body></html>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Karthik
  • 184
  • 1
  • 3
  • 11

2 Answers2

0

Replace

$('<img></img>').attr('src', 'photo.jpg')

With:

$('<a href="something"><img src="photo.jpg" alt="something useful" \/><\/a>');
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks..Now the code is working as per your suggestion but only when the `hide()` is removed. but if `hide()` is removed then while loading the image, at first it is displayed at a position below `
    ` and then it is displayed at exact position as i have also used a preloader before displaying images.
    – Karthik Jul 10 '11 at 15:57
0

Check jQuery live() method
http://api.jquery.com/live/

May be this will be helpful
How to change the href for a hyperlink using jQuery

Community
  • 1
  • 1
Saanch
  • 1,814
  • 1
  • 24
  • 38