jQuery offset() get

Introduction

Set the offset coordinates of the p element equal to the span element.

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*  w  w w  .  j av  a2 s. c o m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").offset($("span").offset());
  });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>

<button>Set</button>

<span style="position:absolute;left:100px;top:150px;">This is a span</span>

</body>
</html>



PreviousNext

Related