user3371049 user3371049 - 1 year ago 91
Javascript Question

How to change the name "data-original" attribute name in images with no ids

Context: I am trying a workaround to the lazyload script that does not work well for my setup.

I am not sure this is realistic but, this is what I have in mind:
On a title section click, I want to change all the attributes of the images contained in the section (so the images show).

From data-original to src.

Here is were I am:


var a = $('#b01').next().find('img').attr("data-original");

// alert (a) // will give me the url of the attr. data-original: (http...)

x = a.getAttribute("data-original");
a.setAttribute("src", x);

This does not work. Could you help?

Answer Source

Try this

   $(this).attr("src", $(this).attr("data-original") ).removeAttr("data-original");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download