Skip to main content

Bug Tracker

Side navigation

#12302 closed bug (invalid)

Opened August 15, 2012 05:59AM UTC

Closed August 15, 2012 09:40AM UTC

Error on attempting to call a .val() or .attr() method on <option>

Reported by: Owned by:
Priority: low Milestone: None
Component: attributes Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:

I'm not sure if this is truly a bug, but common sense tells me an <option> element should have a .val() method.

code sample:

            // console.log(this.attr('value'));
            $(this).css( {"background-color":"Black", "color":"White"} );

Selectors matches a <select> element, then need to process each option value to define a corresponding style.

Uncaught TypeError: Object #<HTMLOptionElement> has no method 'val'

and trying to bypass .val() call by using .attr('value') method gives this:

Uncaught TypeError: Object #<HTMLOptionElement> has no method 'attr'

Sorry, jsfiddle is messed up by our corporate firewall (results in uneditable and unseen [HTML] field), so i have to post an example to jsbin:

Attachments (0)
Change History (2)

Changed August 15, 2012 06:21AM UTC by iDevy <> comment:1

oops, sorry.. my fault...

in .val() selector should have been '$(this)' not 'this' object..

need to get more sleep

Changed August 15, 2012 09:40AM UTC by sindresorhus comment:2

component: unfiledattributes
priority: undecidedlow
resolution: → invalid
status: newclosed