javascript - Not able to set the text in an textarea using jQuery and value method - Stack Overflow

I've got the following markup:<textarea id="hazaa"><textarea>When I execute

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. :)

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. :)

Share Improve this question edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Jun 7, 2013 at 9:33 Konrad VilterstenKonrad Viltersten 39.5k88 gold badges290 silver badges511 bronze badges 1
  • $("#hazaa").val is wrong. – Adil Shaikh Commented Jun 7, 2013 at 9:39
Add a ment  | 

2 Answers 2

Reset to default 3

You need to do this -

setter

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

getter

var val = $("#hazaa").val();
  • http://api.jquery./val/

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

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();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744964266a4603577.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信