1

here is my sample html which is stored in a variable.

var sHtml=''
sHtml='<div class="diagnostic_picture"><img src="test1.gif" /></div>';
sHtml=sHtml + '<div class="diagnostic_picture"><img src="test2.gif" /></div>';
sHtml=sHtml + '<div class="diagnostic_picture"><img src="test3.gif" /></div>';

now i want to know how could i add another attribute called delaySrc to all the images which is stored as html in a variable.

please help me to achieve it using jquery. thanks

Thomas
  • 32,301
  • 119
  • 343
  • 612

1 Answers1

1

You can try this:

$(sHtml).find('img').each(function() {
    $(this).prop('delaySrc', 'something');
    alert($(this).prop('delaySrc')); // just for ensure
});

DEMO

thecodeparadox
  • 84,459
  • 21
  • 136
  • 161
  • thanks for your code....can i write this way $(sHtml).find('img').each(function() { var img = $(this); img.attr("data-original", img.attr("src")); alert(img.attr("src")); // just for ensure }); – Thomas Jun 19 '12 at 09:23