Reputation: 106
I am trying to make a simple toggle but it is not working.And i want it done in javascript not in jquery. Here is my javascript.
<script>
function showhide() {
if (document.getElementById(ptag).style.display = "block") {
document.getElementById(ptag).style.display = "none";
} else {
document.getElementById(ptag).style.display = "block";
}
}
</script>
Here is my HTML.
<input type="button" value="Show hide" onclick="showhide()">
<p id="ptag">Some text here.</p>
I need solution :(
Upvotes: 0
Views: 1161
Reputation: 9357
Change your if
condition to:
if(document.getElementById("ptag").style.display == "block"){
^^^^ string ^^^ double equals
And replace all other references of ptag
to "ptag"
Upvotes: 3