jQuery offsetParent() メソッド

jQuery HTML/CSS Methods jQuery HTML/CSS Methods

<p> 要素の直近の position が設定された親要素の背景色を設定する:

$("button").click(function(){
  $("p").offsetParent().css("background-color","red");
});

Try it yourself »

定義と用法

offsetParent() メソッドは、position が設定された最初の親要素を返します。

チップ: 要素は、jQueryで position が設定されているか、CSS position プロパティ(relative、absolute または fixed) が設定された要素とすることができます。


構文

$(selector).offsetParent()


jQuery HTML/CSS Methods jQuery HTML/CSS Methods