Get the App
SLTechnology News&Howtos  ›  Development  › 

How to remove the html tag from jq

Shulou Source: shulou.com Published: 2022-06-02 08:22:49 09月11日 Update

This article introduces the relevant knowledge of "how to remove the html tag from jq". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Jq remove the html tag method: 1, use remove (), syntax "$(" selector "). Remove ()"; 2, use empty (), syntax "$(" selector "). Empty ()"; 3, use detach (), syntax "$(" selector "). Detach ()".

The operating environment of this tutorial: windows7 system, HTML5&&jquery1.10.2 version, Dell G3 computer.

JQuery remove the html tag

Method 1: use remove ()

The remove () method removes the selected element, including all text and child nodes.

This method also removes the data and events of the selected element.

$(document) .ready (function () {$("button") .click (function () {$("p"). Remove ();})

This is a paragraph.

This is another paragraph.

Remove all P elements

Method 2: use the empty () method

The empty () method removes all child nodes and content of the selected element.

Note: this method does not remove the element itself or its attributes.

$(document) .ready (function () {$("button") .click (function () {$("div"). Empty ();}) Here are some texts.

This is a paragraph in the div block.

This is a paragraph outside the div block.

Remove the contents of the div block

Method 3: use the detach () method

The detach () method removes the selected element, including all text and child nodes. It then retains the data and events.

This method retains copies of the removed elements, allowing them to be reinserted later.

$(document) .ready (function () {$("button") .click (function () {$("p"). Detach ();})

This is a paragraph.

This is another paragraph.

Remove all P elements

This is the end of the content of "how to remove the html tag from jq". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Method element this is paragraph tag content text node grammar selection event data more knowledge practicality achievement next copy dilemma reality. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS Linux Shulou Information OPPO Reno