LoginSignup
0
0

textメソッドについて

Posted at

textメソッドとは?

textメソッドは、jQueryで要素のテキストコンテンツを取得または設定するためのメソッドです。

使用方法

jQueryではCSSだけでなくtextメソッドを用いることでHTMLそのものを変更することができます。textメソッドは、$('セレクタ').text('書き換える文字列');のように記述します。
また、引数を指定せずに用いることで、要素内の文字列を取得することもできます。

<h1>こんにちは</h1>
<p>Progate</p>
//文字列を書き換える場合
$('h1').text('こんばんは');    //h1要素内を引数の文字列で変更

//文字列を取得する場合
var text = $('p').text();   //p要素内の文字列「Progate」を取得
0
0
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
0
0