?
Solved

Jquery get X and Y coordfinates of an elemnet within a DIV

Posted on 2013-06-27
4
Medium Priority
?
193 Views
Last Modified: 2013-07-17
Hi

I have a container element of 980px. I want to find the x and y coordinates of an element within that container element.

Im using .position() .
This retrieves the coordinates in relation to the whole viewport. How can i get the coordinates in relation to the container eleemnt?

Thanks
0
Comment
Question by:coolispaul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39281858
I think you want offset http://api.jquery.com/offset/
0
 

Author Comment

by:coolispaul
ID: 39281871
hmm i tried that but where do you tell it watch element to offset it against?
0
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 1500 total points
ID: 39282335
Works for me
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
	console.log ($('#fred').position());
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div style="width: 200px; height: 200px; border: 1px solid green">
	<div style="left: 30px;top: 17px; position: absolute; width: 50px; height: 29px; background: blue" id="fred">
	</div>
</div>
</body>
</html>

Open in new window

0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39332496
Can you give a bit more info on what the solution was here.
A B grade means the solution given lacked some information or required you to do a good amount of extra work to resolve the problem. When closing the question, the asker should explain why a B grade was awarded.
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question