Skip to content Skip to sidebar Skip to footer

How To Hide/show Div Based On Variable Using Javascript

I am trying to display a div based on the URL parameter. I have to use only html css and javascript. I got it working until the part where the div must be set to display none if th

Solution 1:

You can set the display property using block or none.

document.getElementById('cfiblinks').style.display = 'block'; //Will showdocument.getElementById('cfiblinks').style.display = 'none'; //Will hide

Solution 2:

Try this..

if (myvar == 10102) {

    document.write('The url parameter is: ' + myvar +'     ');
    document.getElementById('cfiblinks').setAttribute("style", "display:block");

} else {
   document.write('The url parameter is not : ' + myvar +'      ');
   document.getElementById('cfiblinks').setAttribute("style", "display:none");
  }

Solution 3:

Try:

document.getElementById('something').style.display = "block";

and

document.getElementById('something').style.display = "none";

Post a Comment for "How To Hide/show Div Based On Variable Using Javascript"