Reputation: 22957
I am trying to obtain the .val()
of a input field within an AJAX loaded box. I absolutely know a value exists, however when I try to access the value using jQuery's .val()
, it always returns undefined.
(Both these console.log
s are fired right after each other.)
console.log(this.content);
console.log($('#sa', this.content).val());
or
console.log(this.content.find('#sa').val());
Returns 'undefined'
Just doing a log on the element shows no value either:
console.log($('#sa', this.content));
I'm at a loss on why I cannot access this value.
There's a million of these types of questions, so feel free to mark as duplicate if you know of one that asks exactly what I'm asking.
Upvotes: 2
Views: 333
Reputation: 16728
jQuery.find looks for descendants, but the element you're looking for isn't a descendant (it's actually part of the collection.)
Try filter instead:
this.content.filter('#sa').val()
Upvotes: 5