How to hide element by id in jQuery

By | May 20, 2021

jQuery has a lot of methods available that can help you in performing task easily without writing multiple lines of codes in JavaScript. In this blog, I am going to share with you multiple tricks, by using, you can hide element by id in jQuery easily.

Lets say, you have a <div> which has assigned id as my_test_div.

<div id="my_test_div"> This is test div. </div>

Hide element by id using jQuery hide() Method

$( document ).ready(function() {
    $('#my_test_div').hide();
});

Using jQuery css() Method

$( document ).ready(function() {
    $('#my_test_div').css('display','none');
});

Using jQuery toggle() Method

$( document ).ready(function() {
    $('#my_test_div').toggle();
});