3

I've got the following markup:

<textarea id="hazaa"></textarea>

When I execute the following JavaScript in the console:

$("#hazaa").value

I get the print-out of what's in the box. However, when I try to execute this:

$("#hazaa").value = "shazoo"

the console notifies me back with shazoo but the text in the box doesn't change. Also, subsequent check of what's in the box returns the old, unaltered value.

It's been a while since I've done any jQuery-ing so it's probably something fairly obvious but I can't think of any resolution. I've googled for suggestions but the best one I've found actually discusses properties that aren't there! What am I missing?!

Executing the following two lines:

$("#hazaa").val
$("#hazaa").val()

produces:

undefined
TypeError: Object # has no method 'val'

I trust fully that I'm to blame for it but I don't how how to proceed. :)

Community
  • 1
  • 1
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438

2 Answers2

3

You need to do this -

setter

$("#hazaa").val("shazoo");

getter

var val = $("#hazaa").val();

Demo --> http://jsfiddle.net/E3kZy/1/

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
0

You can set value by using .val()

Set the value of each element in the set of matched elements.

   $("#hazaa").val('Your text here');

.val()

You can get the value using $("#hazaa").val();

PSR
  • 39,804
  • 41
  • 111
  • 151