LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Discovering position of an element in JavaScript (https://www.linuxquestions.org/questions/programming-9/discovering-position-of-an-element-in-javascript-360795/)

Napalm Llama 09-06-2005 02:15 PM

Discovering position of an element in JavaScript
 
How's it done?

document.getElementById("some_element").style.top contains it once it's been moved, but not before.

Is there any way of finding out the whereabouts without actually setting them yourself first?

pnellesen 09-07-2005 08:43 AM

By "position", do you mean the x-y coordinates of the element in the window, or something else?

Post Modern 09-07-2005 12:38 PM

I think....
 
.
.
I think he means where in the code a particular element is written into the whole composition, like a .jpg reference or how do you find where an element written into the code is located, like a line of script.

It's simple, at least for me - I just add in a few "stop" lines, and at each "stop", when I bring up the index page on my computer (as I'm trying to disect the code for placement) the page stops when it hits the first stop.

IF I'm not where I want to be, I delete the stop, and move it down, and bring up the page again.

Sooner or later, you find the top and bottom of where you want to be, and it doesn't take very long to do....

WHILE I'M DOING THAT:

I add in a few reference lines that don't show up on the page when you open it - like this:

<!-- messages here -->

And, at the end of the section, I add:

<!-- end of section marker -->

You can even get extremely specific, and write in three or four lines of description(s) if you need them, between the left arrow and two dashes and the two dashes and right arrow.

Make your notes as long as you need them, when you bring up the page in a text editor (or whatever you use) they will show up as blue, while the rest of the code is black (or some other color), so they're obvious to see where they are.

And I just keep doing that until I'm thru the entire program, which tells me later on what that particular section has in it if I have to go back in.

And, once I've cut up the code, I can reference them for whatever section I need to change or review by simply refering to the section that's marked with what I'm looking for....

As an interesting note that I've seen written into some pages recently, I notice that SOME references (like a link or a comment) are actually written ONTO a .jpg file, a .gif file or a .png file, with a graphics program, and then linked to with a simple code, like:

<a href-"some jpg or .png file">name of file</a>

That way, when you click on the picture on the page, it acts just like a normal link.

In order to change that kind of link, you actually have to bring up the picture file with your own graphics program, and over write the message put on top of the picture with the authors graphics program.... you remove the addition the original author put on top of the picture, and put your own on it.

If you're working with something like a template, and want to change it so it reads properly for YOUR web site, make sure you either don't change a reference to the original author without permission, or that the change doesn't effect the original authors credit s/he is asking for....

PM
.
.

Napalm Llama 09-07-2005 02:57 PM

Wow...

Thanks for the really detailed response, but the first person was right - I do just want to find the absolute x,y location on the page of some element, such as a picture or a <div>.

Sorry for not being more specific... (but thanks again!)

Post Modern 09-07-2005 03:59 PM

.
.
oops....

You're welcome anyway... at least I tried....

:)

PM


All times are GMT -5. The time now is 12:05 PM.