メソッドでHTML/CSSを操作する
<p id="first">変更前</p> $(function(){ $("p#first").html("<strong>変更後</strong>"); });
jQueryの主なメソッド
メソッド | 意味 |
---|---|
text(...) | テキストを変更する |
text() | テキストを取得する |
html(...) | htmlを変更する |
html() | htmlを取得する |
prepend(...) | 要素内の先頭にhtnlを挿入する |
append(...) | 要素内の最後にhhmlを挿入する |
before(...) | 要素の前にhtmlを挿入する |
after(...) | 要素の後にhtmlを挿入する |
perpendTo(...) | 他の要素内の先頭に要素を移動する |
appendTo(...) | 他の要素内の最後に要素を移動する |
insertBefore(...) | 他の要素の前に要素を移動する |
insertAfter(...) | 他の要素の後に要素を移動する |
wrap(...) | 要素を他の要素で包む |
wrapAll(...) | 要素をまとめて他の要素で包む |
wrapInner(...) | 子要素/テキストを他の要素で包む |
replaceWith(...) | 要素をたの要素に置き換える |
remove() | 要素を削除する |
attr(...,...) | 指定した属性の値を変更する |
attr(...) | 指定した属性の値を取得する |
removeAttr(...) | 指定した属性を削除する |
addClass(...) | class属性を追加する |
removeClass(...) | class属性を削除する |
css(...,...) | 指定したcssプロパティの値を設定する |
css(...) | 指定したcssプロパティの値を取得する |