2
<div id="3" class="dsi" onmousedown="test(3);" ondrop="checkImg('3');dropIt(event,3);" ondragover="event.preventDefault();">

<img src="1.gif" draggable="true" ondragstart="dragIt(event,4);" id="pic4" />

I want to change src value using javascript. There are nine dives and they already have 1 to 9 gif images. How can I add new src values leaving the rest of the things unchanged? (I mean draggable="true" ondragstart="dragIt(event,4);" id="pic4")

function ft1() {
            var imgSrcs = ['2.gif', '1.gif', '3.gif', '4.gif', '5.gif', '6.gif', '7.gif', '8.gif'];
            var myImages = [];
            for (var i = 0 ;i <=((imgSrcs.length)-1);i++) {
                var v = i;
                var img = new Image();
                img.src = imgSrcs[i];
                var div0 = document.getElementById(v+1);
                div0.appendChild(img);
                myImages[v+1] = img;
            }

Using this I can replace div images. But how can I remove first assigned src value and then replace new images?

3

2 Answers 2

2

As stated here, simply do:

document.getElementById("pic4").src="...";
Sign up to request clarification or add additional context in comments.

Comments

0

Try this.

$('.img').attr('src','http://source');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.