Prototype: Change attribute
12,345
Solution 1
var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
img.src = 'newSrc';
});
Solution 2
You can also use the setAttribute function.
var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
img.setAttribute('src','newSrc');
img.setAttribute('width','100px');
});
Author by
user199337
Updated on September 02, 2022Comments
-
user199337 almost 2 years
How can I change a
<img>
with the JS-Library Prototype? I managed it to get the element but I couldn't change the "src":$('item1').getElementsBySelector('img')