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')
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')
Share
Improve this question
edited Jun 11, 2012 at 10:58
James Allardice
166k22 gold badges334 silver badges315 bronze badges
asked Nov 26, 2009 at 14:22
user199337user199337
8,2337 gold badges25 silver badges18 bronze badges
2 Answers
Reset to default 7var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
img.src = 'newSrc';
});
You can also use the setAttribute function.
var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
img.setAttribute('src','newSrc');
img.setAttribute('width','100px');
});