Want to fetch the id of the different div elements on the click of p element using javascript -


I have a page with a p tag and div element, the divis element is set with the display: this is not the case at the beginning , I just want to display the various devices shown below body tags on the click of P tag but I got stuck in the different ID of the division, please help me with this situation. Below is my code i thanks

  & lt; Script & gt; Function toggle (id) // Here is a function that receives various IDs of div {var element = document.getElementById (ID); {if (element [i] .style.display == "none") for {i = 1; i & lt; 3; i ++} {element [i] .style.display = "block"; } And {element [i] .style.display = "none"}}} & lt; / Script & gt; & Lt; Body & gt; & Lt; P onclick = "toggle ('div1')" & gt; Sentence1 & lt; / P & gt; & Lt; P onclick = "toggle ('div2')" & gt; Sentence 2 & lt; / P & gt; & Lt; Div id = "div1" name = "name1" style = "display: none; width: 400px; height: 300px; border: 1px solid black; background color: yellow;" Id = "div1" & gt; Barun component & lt; / Div & gt; & Lt; Div id = "div2" style = "display: none; width: 400px; height: 300px; range: 1px solid black; background color: black;" id = "DIV2" & gt; Bhoopi & lt; / Div & gt; & Lt; / Body & gt; 

You only have one div, so you do not need a loop . Just use

  function toggle (id) // Here is a function that receives different IDs of div {var element = document.getElementById (id); If (element.style.display == "none") {element.style.display = "block"; } And {element.style.display = "none"}}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -