Skip to content

Commit

Permalink
added child elements and element attributes section to Mojo::DOM docu…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
kraih committed Dec 19, 2011
1 parent 6a39daf commit f708e02
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/Mojo/DOM.pm
Expand Up @@ -412,7 +412,7 @@ Mojo::DOM - Minimalistic HTML5/XML DOM parser with CSS3 selectors
# Walk
say $dom->div->p->[0]->text;
say $dom->div->p->[1]->{id};
say $dom->div->children('p')->first->{id};
# Iterate
$dom->find('p[id]')->each(sub { say shift->{id} });
Expand Down Expand Up @@ -513,10 +513,6 @@ L<Mojo::DOM::CSS> are supported.
Element attributes.
# Direct hash access to attributes is also available
say $dom->{foo};
say $dom->div->{id};
=head2 C<charset>
my $charset = $dom->charset;
Expand All @@ -527,16 +523,11 @@ Alias for L<Mojo::DOM::HTML/"charset">.
=head2 C<children>
my $collection = $dom->children;
my $collection = $dom->children('div')
my $collection = $dom->children('div');
Return a L<Mojo::Collection> object containing the children of this element,
similar to C<find>.
# Child elements are also automatically available as object methods
say $dom->div->text;
say $dom->div->[23]->text;
$dom->div->each(sub { say $_->text });
=head2 C<content_xml>
my $xml = $dom->content_xml;
Expand Down Expand Up @@ -653,6 +644,21 @@ Element type.
Alias for L<Mojo::DOM::HTML/"xml">. Note that this method is EXPERIMENTAL and
might change without warning!
=head1 CHILD ELEMENTS AND ELEMENT ATTRIBUTES
In addition to the methods above, many child elements are also automatically
available as object methods, which return a L<Mojo::DOM> or
L<Mojo::Collection> object, depending on number of children.
say $dom->div->text;
say $dom->div->[23]->text;
$dom->div->each(sub { say $_->text });
Direct hash access to element attributes is also possible.
say $dom->{foo};
say $dom->div->{id};
=head1 SEE ALSO
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
Expand Down

0 comments on commit f708e02

Please sign in to comment.