I’m trying to get the title of an option element, but it keeps returning undefined. This also happens for $(this).attr("name")…and $(this).attr("value"), but curiously $(this).val() works (as expected). Yet, I’m able to set the value with $(this).attr("value", "baz").
I’m trying to get the title of an option element, but it keeps returning
Share
thispoints to the<select>element. For the selected option, use:Full code (you can safely unwrap
$opt‘s jquery wrapper, and use$opt.titleand$opt.name, these are safe across all browsers):Another method, the jQuery-way is: