Reputation: 1788
Hey everyone can someone show me how I would be able to grab an element's current position?
Doesn't do much. All it demonstrate is a button click and grabs the item I want references.
I want to be able to grab it's current position so when I click a button i can display something on top of it.
https://jsfiddle.net/Lkmjzy9d/ignore this <code block> apparently this needs to be here when displaying a jsfiddle link??? idk....
Upvotes: 1
Views: 209
Reputation: 1184
If you don't want to use jQuery, you can use
element.getBoundingClientRect().top
Upvotes: 3
Reputation: 7488
You can get an elements position using jQuery position() Check the following code snippet
$(document).ready(function(){
var element = $("#Randomitem");
console.log(element.position());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="myFunction()" id="myButton">Click Me</button>
<span id="Randomitem">Random Item</span>
Hope this helps
Upvotes: 1
Reputation:
CSS isn't a scripting language. Therefore you'll need to use something like jQuery or ReactJS.
Upvotes: 0