Question

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')
Was it helpful?

Solution

var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
    img.src = 'newSrc';
});

OTHER TIPS

You can also use the setAttribute function.

var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
    img.setAttribute('src','newSrc');
    img.setAttribute('width','100px');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top