473,836 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

attribute like offsetTop but showing the absolute distance

Pf
A piece of html code:

<table>
<tr>
<td>
<input type="text" name="myInput" onclick="myFunc tion(this)">
<td>
</tr>
</table>

myFunction(el) {
alert(el.offset Top)
}

Alert shows the distance from input to the top of the table or table cell.
Is there any other attribute which shows the absolute distance from input to
the top of the page ? Because of some reasons I can't add table's and
input's offsetTops.

Best regards,
ABS
Jul 23 '05 #1
4 5556


Pf wrote:
A piece of html code:

<table>
<tr>
<td>
<input type="text" name="myInput" onclick="myFunc tion(this)">
<td>
</tr>
</table>

myFunction(el) {
alert(el.offset Top)
}

Alert shows the distance from input to the top of the table or table cell.
Is there any other attribute which shows the absolute distance from input to
the top of the page ? Because of some reasons I can't add table's and
input's offsetTops.


You can add offsetTop along the offsetParent hierarchy e.g.
var el = ...
var totalOffsetTop = 0;
while (el != null) {
totalOffsetTop += el.offsetTop;
el = el.offsetParent ;
}
I don't think there is a way without adding offsetTop values of
individual elements.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Try this:
/**
* returns the absolute left location of an element.
* param: e: element
* return: an integer representing the offset from left.
*/
function getElementLeftP osition(e){
var x=0;
while(e){
x+=e.offsetLeft +e.clientLeft;
e=e.offsetParen t;
}
return x;
}

/**
* returns the absolute top location of an element.
* param: e: element
* return: an integer representing the offset from top.
*/
function getElementTopPo sition(e){
var y=0;
while(e){
y+=e.offsetTop+ e.clientTop;
e=e.offsetParen t;
}
return y;
}

Jul 23 '05 #3
Pf
sh************* @gmail.com wrote:
Try this: [...]


Thanks a lot. Could you tell me what is e.clientLeft for ? I got NaN as
returned value till I didn't remove it.

ABS
Jul 23 '05 #4
clientLeft Property:

Retrieves the distance between the offsetLeft property and the true
left side of the client area.

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12701
by: Falc2199 | last post by:
Hi all, I am using the "Poistion" attribute to correctly align a column of images that I have on a table. The code looks like so.... <TD valign="top" class="listinglight" align="left"> <A href="somewhere.html" style="position: absolute; left: 25px;"> <IMG src="CopyButton.gif" border="0" /></A> <A href="anywhere.html" style="position: absolute; left: 45px;">
2
3979
by: Mike Mimic | last post by:
Hi! I would like to make something like this: +-----------------+ |A | | | | +----+ | | |B | | | | | |
2
4305
by: Gernot Frisch | last post by:
Hi, when I have this code in my script: pos_y = document.getElementById('holdmenu').offsetTop; The menu get's positioned at the very top of the site - really annoying. On FireFox it works good. If I put this script part at the very end of the body, it works, too. Can you help me what's wrong here?
1
7034
by: vince.guzman | last post by:
Need help with showing Layer 4 after menu times out onmouseout _______________________________________________ <html> <head> <script language="JavaScript"> <!-- function mmLoadMenus() { if (window.mm_menu_0422101100_0) return;
6
7740
by: Francisco | last post by:
Hi all, I have a div (divI) inner another div (divM), when i request the offsetTop of divI (inner) it returns me the top of divI in divM and not the top of divI in the document? Have anyway to get this information? Gratefull Francisco
4
2184
by: rsteph | last post by:
I've found a javascript menu download, I've been tweaking it within a testpage, and getting it to look just right. I finally got everything looking right, all I have to do is alter where the links navigate to. Before I do that I'm trying to get it put into the actual page I want to use it in; right now I've been using a blank html page to test it with. I've done everything just like it is in the test page, but the menu isn't appearing on the...
1
5584
by: Grimm | last post by:
I am developing an internalk inteface that integrates alot of seperate tools into one interface. The current version uses one Iframe inside a div layer for positioning. Currently the seperate web tools do not have the ability to stay active. As you switch from tool to tool the previous information is lost unless you use a Back button. I need to place multiple div layers with I frames in them that can be shown or hidden based on selection. The...
1
2107
by: tromton | last post by:
Hello all, I have a problem with a scrript in safari 3. in mozilla/firefox and opera the problem does not exist. what i try to do: I have a div element with overflow:auto. in the element i have several anchors, wich i can scroll to with several anchor links. this works quite nicely. the div content can be scrolled by a JS-scrolling script. when i click on a anchor link the scrolling script loses its position, so the next time i will...
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9656
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10526
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10237
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9349
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6972
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5641
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4437
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3100
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.