Using the offsetParent Property : Table « HTML « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » HTML » Table 




Using the offsetParent Property
 


/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

John Wiley & Sons CopyRight 2001
*/

<HTML>
<HEAD>
<TITLE>offsetParent Property</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function setImagePosition(){
    var cElement = document.all.myCell
    // Set flag for whether calculations should use
    // client- or offset- property measures. Use
    // client- for IE5/Mac and IE4/Windows; otherwise
    // use offset- properties. An ugly, but necessary
    // workaround.
    var useClient = (cElement.offsetTop == 0
        ((cElement.offsetParent.tagName == "TR"false truefalse
    if (useClient) {
        var x = cElement.clientLeft
        var y = cElement.clientTop
    else {
        var x = cElement.offsetLeft
        var y = cElement.offsetTop
    }
    var pElement = document.all.myCell.offsetParent
    while (pElement != document.body) {
        if (useClient) {
            x += pElement.clientLeft
            y += pElement.clientTop
        else {
            x += pElement.offsetLeft
            y += pElement.offsetTop
        }
        pElement = pElement.offsetParent
    }
    document.all.myDIV.style.pixelLeft = x
    document.all.myDIV.style.pixelTop = y
    document.all.myDIV.style.visibility = "visible"
}
</SCRIPT>
</HEAD>
<BODY onload="setImagePosition()">
<SCRIPT LANGUAGE="JavaScript">
</SCRIPT>
<H1>The offsetParent Property</H1>
<HR>
<P>After the document loads, the script positions a small image in the upper
 left corner of the second table cell.</P>
<TABLE BORDER=ALIGN="center">
<TR>
    <TD>This is the first cell</TD>
    <TD ID="myCell">This is the second cell.</TD>
</TR>
</TABLE>
<DIV ID="myDIV" STYLE="position:absolute; visibility:hidden; height:12; width:12">
<IMG SRC="http://www.java2s.com/style/logo.png" HEIGHT=12 WIDTH=12></DIV>
</BODY>
</HTML>

           
         
  














Related examples in the same category
1.Tabular data in Javascript with hyper link
2.Change the width of a table border
3.Change the cellPadding and cellSpacing of a table
4.Specify frames of a table
5.Change table row height
6.Specify rules for a table
7.Create table caption
8.Deleting table rows
9.Adding table rows
10.Align the cell content in a table row
11.Change the cell content in a table row
12.Vertical align the cell content in a table row
13.Align the cell content in a single cell
14.Vertical align the cell content in a single cell
15.Adding cells to a table row
16.Change the colspan of a table row
17.Insert table row: the uniqueID Property
18.Using the cloneNode Method
19.Cycling Through Table frame Property Values
20.Replacing Table Cell Content
21.Inserting/Removing Row Elements
22.Modifying Table Columns
23.Accessing userProfile Data
24.Cycling Through Table rows Property Values
25.Using the Data Binding record Number Property
26.Transforming JavaScript Data into HTML Tables
27.Transforming JavaScript Data into HTML Tables with HyperLink
28.Create a table
29.Change table border width and cell padding
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.