2

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']

1
  • It should have been [value='footer'], not [@value='footer'] Commented Feb 22, 2013 at 10:14

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I couldn't work out why it wasn't working. The article I was following is obviously a little out of date. I will tick the answer in 12 minutes :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.