What is the remove method in Mojo::DOM?

Overview

The remove method removes the given HTML/XML element. This method is provided by the Mojo::DOM module, which is an HTML/XML DOM parser with CSS selectors.

Syntax

$dom->at('html element')->remove

Return value

This method will remove the given node and return the root or the parent.

Let’s look at an example of this:

Example

use 5.010;
use Mojo::DOM;
# Parse the html
my $dom = Mojo::DOM->new('<div>Inside div <p id="a">Inside paragraph </p></div>');
# remove node p
say $dom->at('p')->remove;

Explanation

  • Line 2: We import the Mojo::DOM module.
  • Line 5: We parse the HTML and store it in the $dom scalar.
  • Line 8: We remove the node p using the remove method and print the returned parent or root element.

Free Resources