JavaScriptのjQueryオブジェクトは、パターンにマッチするHTML要素をオブジェクト化したものである。
一致した要素の集合に要素を追加した新しいjQueryオブジェクトを作成する。
add(selector)
add(elements)
add(html)
add(selection)
add(selector, context)
マッチする要素の前にコンテンツを追加する。
jQueryObject.before(content[,content])
jQueryObject.before(function(index){
/* script */
})
beforeの使用例を次に示す。
<div id="div4">div4</div>
<div id="div5">div5</div>
<div id="div6">div6</div>
<script>
$("#div5").before("<p>Inserted</p>");
</script>
上記の実行結果を示す。
Inserted
マッチする要素の子要素を取得する。マッチする要素の直下にある子要素のみ取得し、子孫要素は取得しない。
jQueryObject.children([selector]){
/* script */
})
引数を省略した場合、無条件にすべての子要素を取得する。
一致した要素のいずれかに、指定されたクラスが割り当てられているかどうかを判定する。
hasClass(className)
コンテンツにパディングを含めた要素の高さを取得または設定する。
jQueryObject.innerHeight()
jQueryObject.innerHeight(value)
jQueryObject.innerHeight(function)
コンテンツ | パディング | ボーダー | マージン | |
---|---|---|---|---|
jQueryObject.height() |
含む | 含まない | 含まない | 含まない |
jQueryObject.innerHeight() |
含む | 含む | 含まない | 含まない |
jQueryObject.outerHeight() |
含む | 含む | 含む | 含まない |
jQueryObject.outerHeight(true) |
含む | 含む | 含む | 含む |
コンテンツにパディングを含めた要素の幅を取得または設定する。
jQueryObject.innerWidth()
jQueryObject.innerWidth(value)
jQueryObject.innerWidth(function)
コンテンツ | パディング | ボーダー | マージン | |
---|---|---|---|---|
jQueryObject.width() |
含む | 含まない | 含まない | 含まない |
jQueryObject.innerWidth() |
含む | 含む | 含まない | 含まない |
jQueryObject.outerWidth() |
含む | 含む | 含む | 含まない |
jQueryObject.outerWidth(true) |
含む | 含む | 含む | 含む |
コンテンツにパディングおよびボーダーを含めた要素の高さを取得または設定する。マージンを含めるかどうかは引数で指定する。
jQueryObject.outerHeight()
jQueryObject.outerHeight(boolean)
jQueryObject.outerHeight(value)
jQueryObject.outerHeight(value, boolean)
jQueryObject.outerHeight(function)
コンテンツにパディングおよびボーダーを含めた要素の幅を取得または設定する。マージンを含めるかどうかは引数で指定する。
jQueryObject.outerWidth()
jQueryObject.outerWidth(boolean)
jQueryObject.outerWidth(value)
jQueryObject.outerWidth(value, boolean)
jQueryObject.outerWidth(function)
一致した要素の集合内の各要素から属性を削除する。
removeAttr(attributeName)
一致した要素の集合のプロパティを削除する。
removeProp(propertyName)
クラスの存在またはstate引数の値に応じて、一致した要素の集合内の各要素から1つ以上のクラスを追加または削除する。
toggleClass(className)
toggleClass(className, state)
toggleClass(classNames)
toggleClass(classNames, state)
toggleClass(function)
toggleClass(function, state)
一致した要素の集合内の最初の要素の現在の値を取得するか、一致したすべての要素の値を設定する。
val()