SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    getting TR number.

    I've created a table
    Code:
    <table>
    <tr><td>nought</tr></td>
    <tr><td>one</tr></td>
    <tr><td>two</tr></td>
    <tr><td>three</tr></td>
    </table>
    and I can use this css to change the table elements
    Code:
    <style type="text/css">tr:hover{orange}</style>
    or this JS
    Code:
    <script type="text/javascript">
    var trs=document.getElementsByTagName("tr" )
    for(i=0;i<trs.length;i++) {
    trs[i].onmouseover=function(){ this.style.background='orange' }
    trs[i].onmouseout=function(){ this.style.background='none' }}
    </script>
    But what I'm trying to do is get the index number of the TR, so when you mouseover the first tr the value is 0; and the second,1 etc.
    I tried
    Code:
    trs[i].onmouseover=function(){ alert(i) }
    but its always the last number of the loop.
    Any suggestions?
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use TABLE.rows (a collection) or TR.rowIndex
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    cheers Beetle, once-again. Works perfectly!
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


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
  •