{"id":5405,"date":"2020-02-10T12:48:17","date_gmt":"2020-02-10T07:18:17","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5405"},"modified":"2026-11-16T13:07:22","modified_gmt":"2026-11-16T07:37:22","slug":"jquery","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/jquery\/","title":{"rendered":"jQuery empty() and remove() Methods: Easy Guide with Examples"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date:<\/strong> 10 February 2020<br><strong>Last Updated:<\/strong> 11 November 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>jQuery&#8217;s empty() and remove() methods<\/strong> are commonly used to remove HTML content and elements from a webpage. Both methods help developers manipulate the DOM by removing unwanted elements. However, they differ in how they remove selected elements and their child content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, they work differently:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>empty()<\/code> method removes all child elements and content inside the selected element while keeping the selected element itself.<\/li>\n\n\n\n<li>The <code>remove()<\/code> method removes the selected element along with all its child elements and content.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will explore how to use jQuery <code>empty()<\/code> and <code>remove()<\/code> methods with simple HTML and JavaScript examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. jQuery empty() Method<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The jQuery <code>empty()<\/code> method removes all child elements and text content from the selected HTML element. The selected element itself remains in the document.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(selector).empty();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>selector<\/code> specifies the HTML element whose child content needs to be removed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Using the empty() Method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The following example demonstrates how to remove all the content inside the <code>&lt;body&gt;<\/code> element when a button is clicked.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html>\n&lt;html>\n&lt;head>\n    &lt;title>jQuery empty() Example&lt;\/title>\n    &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.7.1.min.js\">&lt;\/script>\n\n    &lt;script>\n        $(document).ready(function() {\n            $(\"button\").click(function() {\n                $(\"body\").empty();\n            });\n        });\n    &lt;\/script>\n&lt;\/head>\n\n&lt;body style=\"background-color: yellow;\">\n    &lt;div>\n        &lt;center>\n            &lt;h3>Hello&lt;\/h3>\n            &lt;h3>jQuery empty() Method&lt;\/h3>\n            &lt;button>Click&lt;\/button>\n        &lt;\/center>\n    &lt;\/div>\n&lt;\/body>\n&lt;\/html><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Before clicking the button:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The webpage displays the heading text and a button on a yellow background.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-1.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"736\" height=\"288\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-1.png\" alt=\"jQuery's empty() and remove() methods example showing headings and a button before removing the body content.\" class=\"wp-image-13142\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-1.png 736w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-1-300x117.png 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>After clicking the button:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>empty()<\/code> method removes all the content inside the <code>&lt;body&gt;<\/code> element. The body element itself remains.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-2.png\"><img decoding=\"async\" width=\"752\" height=\"252\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-2.png\" alt=\"jQuery's empty() and remove() methods output showing the body content cleared after clicking the button.\" class=\"wp-image-13143\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-2.png 752w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-2-300x101.png 300w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">2. jQuery remove() Method<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The jQuery <code>remove()<\/code> method removes the selected HTML element from the DOM, including all its child elements and content.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(selector).remove();<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>selector<\/code> specifies the HTML element that needs to be removed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also use an optional filter parameter to remove elements that match a particular condition.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$(selector).remove(filter);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Using the remove() Method<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, clicking the button removes the paragraph element with the class name <code>test<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html>\n&lt;html>\n&lt;head>\n    &lt;title>jQuery remove() Example&lt;\/title>\n    &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.7.1.min.js\">&lt;\/script>\n\n    &lt;script>\n        $(document).ready(function() {\n            $(\"button\").click(function() {\n                $(\"p.test\").remove();\n            });\n        });\n    &lt;\/script>\n&lt;\/head>\n\n&lt;body style=\"background-color: pink;\">\n    &lt;center>\n        &lt;div class=\"mycon\">\n            &lt;p>Welcome&lt;\/p>\n            &lt;p class=\"test\">Remove this line&lt;\/p>\n            &lt;h3>Hello&lt;\/h3>\n            &lt;h3>jQuery remove() Method&lt;\/h3>\n            &lt;button>Click&lt;\/button>\n        &lt;\/div>\n    &lt;\/center>\n&lt;\/body>\n&lt;\/html><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Before clicking the button:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The webpage displays two paragraphs, two headings, and a button on a pink background.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-4.png\"><img decoding=\"async\" width=\"757\" height=\"342\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-4.png\" alt=\"jQuery's empty() and remove() methods example displaying paragraphs and headings before removing the selected paragraph.\" class=\"wp-image-13145\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-4.png 757w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-4-300x136.png 300w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>After clicking the button:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>remove()<\/code> method removes the paragraph with the class name <code>test<\/code>. The remaining content stays on the webpage.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"290\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-5.png\" alt=\"jQuery's empty() and remove() methods output showing the selected paragraph removed while the remaining HTML elements stay visible.\" class=\"wp-image-13146\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-5.png 750w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/image-5-300x116.png 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3. Difference Between jQuery&#8217;s empty() and remove() methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both methods remove content from a webpage, but their functionality is different.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Feature<\/th><th>empty()<\/th><th>remove()<\/th><\/tr><tr><td>Purpose<\/td><td>Removes child elements and content<\/td><td>Removes the selected element<\/td><\/tr><tr><td>Selected element<\/td><td>Remains in the DOM<\/td><td>Is removed from the DOM<\/td><\/tr><tr><td>Child elements<\/td><td>Removed<\/td><td>Removed along with the parent<\/td><\/tr><tr><td>Common usage<\/td><td>Clearing container content<\/td><td>Removing unwanted HTML elements<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The jQuery <code>empty()<\/code> and <code>remove()<\/code> methods are useful for dynamically managing HTML elements.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <code>empty()<\/code> when you want to clear the content inside an element while keeping the element itself.<\/li>\n\n\n\n<li>Use <code>remove()<\/code> when you want to delete the selected element along with its content.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding the difference between these methods helps developers manage webpage content more effectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/jquery-hide-and-show\/\">jQuery Hide and Show<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Official Documentation<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/api.jquery.com\/empty\/\" target=\"_blank\" rel=\"noopener\">jQuery empty() Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/api.jquery.com\/remove\/\" target=\"_blank\" rel=\"noopener\">jQuery remove() Documentation<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Build Better Web Solutions with Pheonix Solutions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Looking for reliable JavaScript development and web application solutions?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/web-development\/\"><strong>Pheonix Solutions<\/strong><\/a> provides web development, application development, cloud solutions, and DevOps services to help businesses build efficient and scalable digital solutions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our experts can help you develop interactive web applications, implement modern JavaScript functionality, and improve your application performance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/pheonixsolutions.com\/contact\"><strong>Contact our experts<\/strong><\/a> to discuss your project requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: 10 February 2020Last Updated: 11 November 2026 Introduction jQuery&#8217;s empty() and remove() methods are commonly used to remove [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[752,751,753],"class_list":["post-5405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-architecture","tag-empty","tag-jquery","tag-remove","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/shn2x7-jquery","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/jQuery-empty-and-remove-Guide.png","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5405"}],"version-history":[{"count":3,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5405\/revisions"}],"predecessor-version":[{"id":13508,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5405\/revisions\/13508"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media\/13505"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}