13
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

.htmlと.textと.valで混乱したので整理する

Last updated at Posted at 2016-01-05

#違い

  • .html(): 引数をHTMLとして書き換え。タグが有効になる。
  • .text(): 引数を文字列として書き換え。タグはエスケープされて無効になる。
  • .val(): 引数をvalueとして書き換え。

#例


<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>

<dev id='html'></dev>
<dev id='text'></dev>
<input id='val' value='none'>

<script>
  $('#html').html('<b>太字になる</b>');
  $('#text').text('<b>太字にならない</b>');
  $('#val').val('書き換え');
</script>

###出力
スクリーンショット 2016-01-05 6.37.34 PM.png

#参考
https://q-az.net/none-jquery-html-text-val/
http://wp-p.info/tpl_rep.php?cat=js-biginner&fl=r13

13
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?