Try to search your question here, if you can't find : Ask Any Question Now ?

How to make onclick function create images in the same div?

HomeCategory: stackoverflowHow to make onclick function create images in the same div?
julie asked 2 weeks ago

this code is part of an onclick function . the function supposed to show some calculation results and corresponded images in the div (“gallerym”) . every thing works but when the user click on the button to trigger the onclick multiple times it will create more divs (gallerym),

i was able to make the function work only once with : this.onclick=null but now the user is restricted only to one click (after which he will have to refresh the page to use it again )

my question is : HOW TO MAKE SURE THAT THE FUNCTION WILL CREATE THE IMAGES IN THE SAME DIV WITHOUT CREATING NEW DIVS ?

THANK YOU!

var inputgal = document.getElementById('cmbar').value;
if (inputgal > 10 && inputgal <= 100) {
   var img = document.createElement("img");
   img.src = "../images/gallery/10cmto100cmm600x600.jpg";
   var src = document.getElementById("gallerym");
   src.appendChild(img);
} else if (inputgal > 100 && inputgal <= 1000) {
      var img = document.createElement("img");
      img.src = "../images/gallery/1mto10mm600x600.jpg";
      var src = document.getElementById("gallerym");
      src.appendChild(img);
}
1 Answers
Best Answer
Mannu answered 2 weeks ago
Your Answer

4 + 17 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com