SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    doRighteousDeeds++
    Join Date
    Aug 2006
    Location
    تركيا Turkey Türkiye
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <td><img src="i.jpg" onclick="alert(this.style.left)"></td>

    Code:
    <style type="text/css">
    img { width: 100px; height:100px;}
    </style>
    <body>
    <table>
    <tr>
    <td><img src="a.jpg"></td><td><img src="b.jpg"></td><td><img src="c.jpg"></td>
    </tr>
    <tr>
    <td><img src="d.jpg"></td><td><img src="e.jpg"></td><td><img src="f.jpg"></td>
    </tr>
    <tr>
    <td><img src="g.jpg"></td><td><img src="h.jpg" onclick="alert(this.style.offsetLeft)"></td><td><img src="i.jpg" onclick="alert(this.style.left)"></td>
    </tr>
    </table>
    </body>
    
    </html>
    I tried
    alert(this.style.offsetLeft)
    but it displays "undefined".
    What is distance between left margin of page and i.jpg? How can I find out it?

  2. #2
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this code...
    Code:
    function l(el) {
    	var tmp = el.offsetLeft;
    	el = el.offsetParent;
    	while (el) {
    		tmp += el.offsetLeft;
    		el = el.offsetParent;
    	}
    	return tmp;
    }
    With...
    Code:
    alert(l(this))

  3. #3
    doRighteousDeeds++
    Join Date
    Aug 2006
    Location
    تركيا Turkey Türkiye
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the DtTvB,
    Thanks..
    It is working as I expected.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •