1

So I am new to JavaScript and jQuery and I can't figure out why my variables are "undefined."

This is what I am doing: http://jsfiddle.net/krECX/15/

What I don't understand is why the variable $asdf is undefined when I call the $asdf.length in this function:

function func() {
   var $asdf = $('#inp').value;
   $('#divOfDoom').hide().html("" + $asdf.length).fadeIn('fast');
}

I'm sure I'm doing something stupid but every example I have found does something identical to my eyes.

What I have tried: var $asdf = createInstance(); alert('' + $asdf); returns 'undefined' regardless of what is in the input box.

Any advice is appreciated.

2 Answers 2

5
var $asdf = $('#inp')[0].value

or

var $asdf = $('#inp').val()
Sign up to request clarification or add additional context in comments.

1 Comment

@sparks Mixing jQuery and JavaScript is a problem that lots of people have trouble with even when they're only new to 1 side of the coin! Keep it up ;)
3

Incorrect jQuery syntax:

$('#inp').val();

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.