Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change images of each div individually?
    primarykey
    data
    text
    <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"&gt;&lt;/script&gt; &lt;title&gt;Javascript Create Div Element Dynamically&lt;/title&gt; &lt;style type="text/css"&gt; .ex { width:200px; position: relative; background-color :#CCC; height:150px; padding:10px; margin:5px; left-margin:0px; float :left; } #newdiv { width:800px; height:800px; border:1px solid #000; } .myimage { height: 80; width: 80; top:100; margin:5px; } .border { border:1px solid #000; } &lt;/style&gt; &lt;script&gt; cc = 1; function changeimage() { if (cc == 0) { cc = 1; $('.myimage').attr('src', 'images/plus.png'); } else if (cc == 1) { cc = 2; $('.myimage').attr('src', 'images/plus2.png'); } else if (cc == 2) { cc = 3; $('.myimage').attr('src', 'images/plus2.png'); } else { cc = 0; $('.myimage').attr('src', 'images/plus2.png'); } } &lt;/script&gt; &lt;script type="text/javascript" language="javascript"&gt; var i = 0; function createDiv() { if (i &lt; 6) { var divTag = document.createElement("div"); divTag.id = "div1"; divTag.setAttribute("align", "left"); divTag.style.margin = "0px auto"; divTag.className = "ex"; divTag.innerHTML = "&lt;img class='myimage' onclick='changeimage()' border='0' src='images/white_contact.png' width='100' height='180' /&gt;"; document.getElementById("newdiv").appendChild(divTag) } i++; $(".ex").draggable({containment: 'parent', cursor: 'pointer', opacity: 0.6}); $(".ex").droppable({hoverClass: 'border'}); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p align="left"&gt; &lt;b&gt;Click this button to create div element dynamically:&lt;/b&gt; &lt;input id="btn1" type="button" value="create div" onClick="createDiv();" /&gt; &lt;div id = "newdiv"&gt; &lt;/div&gt; &lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>after I add the 6 DIV, I click on one DIV, all images will change, now I want to change the image of each div individually, I am running out of time. Can somebody show me which part goes wrong, and let me the solution, thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload