jQuery text()の例

jQuery text()の例

jQuerytext()は、一致したすべての要素のコンテンツを取得するために使用されます。一方、text(‘new text’)は、一致したすべての要素のテキストコンテンツを置換または設定するために使用されます。

例えば、

TEXT 1
TEXT 2

1. $(‘.TClass’).text()

これにより、一致した要素のすべての内容が結合され、戻り値として「TEXT 1 TEXT 2」が取得されます。 html()とは異なり、最初の要素のコンテンツのみを取得します。

2. $(‘.TClass’).text(‘This is new text‘)

すべてのhtmlタグ< and > will be replace with < and >、html効果は適用されません。

This is new text
This is new text

jQuery text()の例









  

jQuery text() example

Text ABC ....
Text ABC 2....