How to show/hide elements using javascript equivalent to jQuery.show() and hide() DOM?

You can show or hide specific elements with native javascript without using jQuery.

<div class="mydiv">Content Goes here</div>

With jQuery, you can simply do it,

jQuery(‘.myDiv’).show() equivalent to Javascript is,

document.querySelector(‘.myDiv’).style.display = none;

The same in jQuery hide a specific element, jQuery(‘.myDiv’).hide()

Equivalent to Javascript is,

document.querySelector(‘.myDiv’).style.display = block;

You need to be careful while using Javascript native, You first need to check current element is exist or not using if conditions and then you can add style to it.

if (document.querySelector('.myDiv')) {
    document.querySelector('.myDiv').style.display = block;
}

You can fetch the specific element DOM node by, document.querySelector(selector) where the selector is the class name, ID, or any attribute of the HTML Tag.