Please Login or Register to continue.


I want to hide or remove the HTML form on button click using the jQuery JavaScript library. How can I display a message after hiding a form using the jQuery library? I am creating a form in HTML and using jQuery, a JavaScript library. I have a situation where I want to hide an HTML form on a button click. How can I hide a form and display any message or alert message using the jQuery JavaScript library?

(2.4K Points)
in jquery


1 Answer
(3.4K Points)

Hiding and removing a form can be done with the jQuery JavaScript library. We use jQuery hide() or remove() function to hide and remove a form.

Difference between jQuery hide() and remove() function

jQuery hide() - If you use the hide() function, it adds display none inline CSS to the form or div block using an id or class name. You can easily check the form code by inspecting elements in the browser. 

jQuery remove() - The remove() method is used to remove form code. You cannot see the form code by inspecting elements. It removes the whole div block, and form block where you have given the id or class name.  

You can display a message using jQuery html() or append() methods- 

Let's remove the HTML form and display a message. 

<!DOCTYPE html>
   <title>Hide or remove a form and display a message in jQuery</title>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script type="text/javascript">
        $("#message").html("Thank you for message.We will reply you soon/shortly."); 
	<p id="message"></p>
<form action="" id="my_form">
   <input type="text" name="name" id="name"><br>
   <textarea name="email" id="email"></textarea><br> 
   <textarea name="address" id="address"></textarea><br>
   <button type="button" name="submit_btn" id="submit_btn">Submit</button>

In the above example, we have created a form with an id. You can use jQuery hide() method like this - 


Execute the above code and click on submit button. You will get an output - The form will remove or hide and display a message using the jQuery JavaScript library. 

You can reset all form fields with a button click in jQuery. In this way, you can hide or remove a form using jQuery. 


Related Questions :-

Your Answer

You can post your answer after login..