javascript - onclick of a list item display the image and on second click on the same gives the value -


print=console.log;  var elements = document.getelementsbyclassname("list");  (i = 0; < elements.length; i++) { elements[i].onclick = show; }    function show(event) {  	var targetnode = event.target;  	var element = targetnode.firstchild;  	print("target is", targetnode);  	print("child node is", element);  	displayonpage(element); //print(targetnode.childnodes[0]);  }  function displayonpage(element) {  	var value = element;  	print("the value function came is", value);  	var onpage = document.getelementbyid("photoframe");    	if (!onpage.haschildnodes()) {  		onpage.appendchild(value);  	} else replace(onpage, value); //print("the value here is", value);  }  function replace(onpage, image) {  	img = image;  	page = onpage;  	page.removechild(page.childnodes[0]);  	page.appendchild(img);  	print("the value came page is", img);    }
.menu{width:80%;margin-left:auto;margin-right:auto;height:50px;}        ul{list-style:none;padding:0;margin-left:auto;margin-right:auto;line-height:2em;      display: block;}        ul li a{text-decoration: none; color: white; display:block;}        ul       li{float:left;width:200px;background-color:black;opacity:0.6;text-align: center;       color: white;}        ul li li:hover{background-color: red;}        ul li ul li{display: none;}        ul li:hover ul li{display: block;}        ul li img{display: none;}        .inner{height:150px;width:80%;margin-right:auto;margin-left:auto;}        #photoframe {width:80%; margin-right: auto; margin-left: auto;}
<!doctype html>      <html>      <head><title>photo frame</title>      <link href="style.css" rel="stylesheet" type="text/css">      </head>      <body>      <div class="menu">      <div class="inner">      <ul >      <li>mountains      	<ul>      	<li class="list"><img src="img/mountainsone.jpg" alt="image1" width="500" height="400"/>mount everest</li>      	<li class="list"><img src="img/mountainstwo.jpg" alt="image2" width="500" height="400"/>himalayas</li>      	<li class="list"><img src="img/mountainsthree.jpg" alt="image3" width="500" height="400"/>mount perk</li>      	</ul>      </li>      </ul>        <ul id="rivers">	      <li>rivers      	<ul>      	<li class="list"><img src="img/riversone.jpg" alt="image4" width="500" height="400"/>ganga</li>      	<li class="list"><img src="img/riverstwo.jpg" alt="image4" width="500" height="400"/>krishna</li>      	</ul>      </li>      </ul>        <ul id="lakes">      <li>lakes      	<ul>      	<li class="list"><img src="img/lakesone.jpg" alt="image5" width="500" height="400"/>tungabhadra</li>      	<li class="list"><img src="img/lakestwo.jpg" alt="image5" width="500" height="400"/>kaveri</li>      	</ul>      </li>      </ul>      </div>      <div id="photoframe" ></div>      </div>      <script src="photoalbum.js" >      </script>      </body>      </html>


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -