.Maui Blog

jQuery to pure Javascript examples – 3

In these examples we see how easy it is to display, hide or use the toggle without jQuery.

Hide an item 

// jQuery 
$("#myElm").hide();

// Pure javascript
document.getElementById("myElm").style.display = "none";

Show an item

// jQuery 
$("#myElm").show();

// Pure javascript
document.getElementById("myElm").style.display = "";

Toggle

// jQuery
$("#myElm").toggle();

// Pure javascript
var my_elm = document.getElementById("myElm")
my_elm.style.display = (my_elm.style.display == "none" ? "" : "none");
Exit mobile version