Domanda

Come posso cambiare un <img> con JS-Library Prototype? Sono riuscito a ottenere l'elemento ma non sono riuscito a cambiare & Quot; src & Quot ;:

$('item1').getElementsBySelector('img')
È stato utile?

Soluzione

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

Altri suggerimenti

Puoi anche usare la funzione setAttribute.

var imgs = $('item1').getElementsBySelector('img');
imgs.each(function(img) {
    img.setAttribute('src','newSrc');
    img.setAttribute('width','100px');
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top