Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - Select option

Tags:

jquery

I have 2 buttons that fire the same form which appears over the page. I would like a dropdown option to change depending on which button is fired.

What am I doing wrong?

var settings = $(this).attr('rel');
$("select[@name='menu'] option[@value='"+settings+"']").attr("selected","selected");

Error

Error: uncaught exception: Syntax error, unrecognized expression:[@value='footer']

like image 781
JasonS Avatar asked Mar 21 '26 19:03

JasonS


1 Answers

You can just do this:

$("select[name='menu']").val($(this).attr('rel'));

Using .val() is a much quicker way...but your error is occuring because the @ was removed from attribute selectors in jQuery 1.3, it's just [name='menu'] and [value='myValue'] now.

like image 120
Nick Craver Avatar answered Mar 25 '26 01:03

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!