Solved

Jquery hanling position error

Posted on 2014-01-29
3
205 Views
Last Modified: 2014-01-29
Hello experts
I 'm trying to use the position of one div so that i can add a new div in an absolute position using the left and top values of the first one
My code:
var position = $('#' + nextdiv).position();
left1 = position.left;alert(left1);
left2 = 186;
left = left1 + left2 ;alert(left);
top1 = position.top;alert(top1);
top2 = 10;
top = top1 + top2; alert(top);

left1 alert is 0 , that is ok
left alert is 186 , that is ok too
top1 alert is 50
but top alert is [object window]  instead of 60
Any help?
0
Comment
Question by:Panos
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
You can't use 'top' as a variable name. Change it to something else:

topTotal = top1 + top2;
alert(topTotal);

Open in new window

0
 
LVL 2

Author Comment

by:Panos
Comment Utility
Thank you Chris Stanyon
It solved the problem
0
 
LVL 2

Author Closing Comment

by:Panos
Comment Utility
Thank you
regards panos
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now