The children
method gets all child elements for the given element. This method is provided by the Mojo::DOM
module— an HTML/XML DOM parser with CSS selectors.
$dom->children
This method will return the Mojo::Collection
, which contains the Mojo::DOM
objects.
The given HTML is as follows:
<div>
Inside div
<p id="a">Inside first paragraph </p>
<p id="b">Inside second paragraph</p>
</div>
If we get the children for the given HTML using the children
method, the output will be as follows:
div
use 5.010;use Mojo::DOM;# Parse the htmlmy $dom = Mojo::DOM->new('<div>Inside div <p id="a">Inside first paragraph </p><p id="b">Inside second paragraph</p></div>');# Get childrensay $dom->children->map('tag')->join("\n");print "Children for div element \n";#Get children for specific elementsay $dom->at('div')->children->map('tag')->join("\n");
Mojo::DOM
module.$dom
.div
using the children
method. Then, we print them.