I have a html document which uses object tag with src attribute. But I need to replace src(attribute name) with “data” (attribute name).
Is it possible to do so using JavaScript?
All I referred shows that we can change the attribute values, but I couldnt find any method to replace attribute node name.
Could someone please help
You will have to get the
srcattribute value and set that to thedataattribute value.You can use
.removeAttribute()if you want to get rid of thesrcattributes.Something like this:
jsFiddle example
If you want to do a bunch of elements, just select them and do a for loop. For example going over all
divs:jsFiddle example
.getAttribute()
.removeAttribute()
.setAttribute()