javascript - How to replace src attribute name with data attribute name -


i have html document uses object tag src attribute. need replace src(attribute name) "data" (attribute name).

is possible using javascript? referred shows can change attribute values, couldnt find method replace attribute node name.

could please help

you have src attribute value , set data attribute value.

you can use .removeattribute() if want rid of src attributes.

something this:

var att = element.getattribute("src"); element.setattribute("data", att); element.removeattribute("src"); 

jsfiddle example


if want bunch of elements, select them , loop. example going on divs:

var att, i, elie = document.getelementsbytagname("div");  (i = 0; < elie.length; ++i) {     att = elie[i].getattribute("src");     elie[i].setattribute("data", att);     elie[i].removeattribute("src");         } 

jsfiddle example



.getattribute()
.removeattribute()
.setattribute()


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -