HTML::DOM::Element::Option - A Perl class for representing 'option' elements in an HTML DOM tree
use HTML::DOM; $doc = HTML::DOM->new; $elem = $doc->createElement('select'); $elem->focus(); $elem->blur(); # $elem->add(...) # not yet # $elem->remove(...) # implemented $elem->options; # a list of 'option' elements $elem->name('foo') # set attribute $elem->type; # get attribute $elem->tagName; # etc.
This class implements 'select' elements in an HTML::DOM tree. It implements the HTMLSelectElement DOM interface and inherits from HTML::DOM::Element (q.v.).
In addition to those inherited from HTML::DOM::Element and its superclasses, this class implements the following DOM methods:
Each of these returns the corresponding HTML attribute (the 'selected' attribute in the case of
defaultSelected). If you pass an argument, it will become the new value of the attribute, and the old value will be returned.
Returns the form containing this input element.
Returns the option's text label.
Returns the index of this option in it's 'select' element's
optionsarray. You can pass an argument to set it. In that case, the option will be moved to a different place in the tree. (This is actually contrary to the DOM Level 2 specification, which makes it read-only, but Level 1 supported this, and I find feature deletion very disagreeable.)
Returns a boolean indicating whether the option is selected. If an argument is passed, it becomes the new state and the old is returned.
Returns the value of the option, that is, the 'value' attribute, if present, or the text content otherwise.
If the calling package is HTML::Form or WWW::Mechanize, the return value will be undef if the option is not selected. With an undef argument the option will be deselected. If an argument is given that is the same as the value, the box will be checked. If any other argument is passed, it will die.
In addition, the following methods are provided for compatibility with
Returns the string 'option'.
Returns the name of the enclosing 'select' element.
This returns a list with
undeffor the first element and the option's value for the second.
Returns a list of two items: (0) the name of the field and (1) the value, *if* it is selected.