I'm trying to get the value of an input text field using
var $rel = '#'+$(this).attr('rel');
but it returns nothing when I test it with
alert($rel.val());
Example: http://jsfiddle.net/59VmX/
I'm trying to get the value of an input text field using
var $rel = '#'+$(this).attr('rel');
but it returns nothing when I test it with
alert($rel.val());
Example: http://jsfiddle.net/59VmX/
'#'+$(this).attr('rel'); // This is just a string
supposed to be
$('#'+$(this).attr('rel')); OR // $('#'+ this.rel);
You need to encase it as a jQuery object if you want to use val method on the object
$('#' + this.rel)Here is a working fiddle , In your old fiddle ,jquery is not loaded and:
Instead of this :
var $rel = '#'+$(this).attr('rel');
alert($rel.val());
It should be :
var $rel = $(this).attr('rel');
alert($rel);
this.relinstead of$(this).attr('rel')and wrap it in jquery to get val().Frameworks & Extensionswhen using jQuery with jsFiddle.