Prototype: change attribute

How can I change <img>using a prototype JS library? I managed to get the item, but I could not change the "src":

$('item1').getElementsBySelector('img')
+3
source share
2 answers
var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
    img.src = 'newSrc';
});
+6
source

You can also use the setAttribute function.

var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
    img.setAttribute('src','newSrc');
    img.setAttribute('width','100px');
});
+7
source

Source: https://habr.com/ru/post/1724008/


All Articles