0

How can you make a javascript variable and use it with jQuery?

I use the following command unsuccessfully in trying to get the POST data out of the var answer. I can access the variable in HTML by $_POST['answer'].

var answer = $('#answer').val();

I use this variable in this code

jQuery('div.answer_' + $answer + ' a.delete_answer')
           .live('click', function(){
1
  • 1
    FYI. Javascript != jquery. jQuery is a javascript framework with functionality to manipulate the DOM. Javascript is the language in which jQuery is written. The variable would be a javascript variable, not a jQuery variable. Commented Aug 29, 2009 at 12:31

1 Answer 1

2

You should be doing:

var $answer = $('#answer').val();

You have a '$' in your selector. You would have to remove the '$' in the selector if you don't want a $ in your variable.

See this:

The $ dollar sign

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.