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');
});
Share:
12,345
user199337
Author by

user199337

Updated on September 02, 2022

Comments

  • user199337
    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')