开发者

Prototype: Change attribute

开发者 https://www.devze.com 2022-12-12 09:36 出处:网络
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\":

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').getEle开发者_StackOverflow社区mentsBySelector('img')


var 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');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号