
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Remove and add new HTML Tags with JavaScript?
To remove and add new HTML tags, use the concept of hide() and show().
Let’s say the following are our buttons −
<button type="submit" id="hide">Click Me To hide above content </button> <button type="submit" id="show">Click Me To show above content </button>
To remove and add tags on button clicks, use hie() and show() −
$(document).ready(function(){ $("#hide").click(function(){ $("h1").hide(); }); $("#show").click(function(){ $("h1").show(); }); });
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initialscale=1.0"> <title>Document</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <h1>Test JavaScript</h1> <button type="submit" id="hide">Click Me To hide above content </button> <button type="submit" id="show">Click Me To show above content </button> <script> $(document).ready(function(){ $("#hide").click(function(){ $("h1").hide(); }); $("#show").click(function(){ $("h1").show(); }); }); </script> </body> </html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.
Output
This will produce the following output −
Case 1
When you click on the button “Click Me To hide above content”, you will get the following output.
Case 2
When you click on the button “Click Me To show above content”, you will get the following output.
- Related Articles
- How to remove HTML Tags with RegExp in JavaScript?
- How to remove html tags from a string in JavaScript?
- How to add and remove HTML attributes with jQuery?
- HTML5 New Tags
- How to add a new element to HTML DOM in JavaScript?
- How to add and remove names on button click with JavaScript?
- Disable browser caching with meta HTML tags
- Is there a way to add/remove several classes in one single instruction with classList in HTML and JavaScript?
- How to remove the HTML tags from a given string in Java?
- HTML Deprecated Tags
- Add oninput attribute to HTML element with JavaScript?
- How can I add an attribute into specific HTML tags in jQuery?
- How to Add and Remove Value Onclick Event in HTML?
- How To Change Text Inside All HTML Tags Using JavaScript
- How to remove and add new YouTube video thumbnail using YouTube Mobile editor?

Advertisements