Bug Tracker

Modify

Ticket #12302 (closed bug: invalid)

Opened 9 months ago

Last modified 9 months ago

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

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

Description

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:

$('[name="attr/ca_internal:string:ignore_empty"]').children().each(function()
       { 
            console.log(this.val());
            // 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:  http://jsbin.com/adabol/1/edit

Change History

comment:1 Changed 9 months ago by iDevy <i@…>

oops, sorry.. my fault... in .val() selector should have been '$(this)' not 'this' object.. need to get more sleep

comment:2 Changed 9 months ago by sindresorhus

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to attributes

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.