How to read the classname of the table header

Discussion in 'Javascript' started by Stefan Mueller, Dec 19, 2009.

  1. I've several tables. The header row of each table looks like
    <th class = "style_table1_header1">
    <div class = "style_column1"
    onMouseover = "alert(this.className)">
    Header of Column 1 in Table 1
    </div>
    </th>

    <th class = "style_table1_header2">
    <div class = "style_column2"
    onMouseover = "alert(this.className)">
    Header of Column 2 in Table 1
    </div>
    </th>

    ...

    If you move the mouse pointer over the first header in table 1 'alert
    (this.className)' in the onMouseover event displays 'style_column1'.
    I there also a way to display the classname of <th> (in this example
    'style_table1_header1')?
    Stefan Mueller, Dec 19, 2009
    #1
    1. Advertising

  2. Stefan Mueller

    RobG Guest

    On Dec 20, 9:08 am, Stefan Mueller <> wrote:
    > I've several tables. The header row of each table looks like
    >   <th class = "style_table1_header1">
    >     <div class = "style_column1"
    >       onMouseover = "alert(this.className)">
    >       Header of Column 1 in Table 1
    >     </div>
    >   </th>
    >
    >   <th class = "style_table1_header2">
    >     <div class = "style_column2"
    >       onMouseover = "alert(this.className)">
    >       Header of Column 2 in Table 1
    >     </div>
    >   </th>
    >
    >   ...
    >
    > If you move the mouse pointer over the first header in table 1 'alert
    > (this.className)' in the onMouseover event displays 'style_column1'.
    > I there also a way to display the classname of <th> (in this example
    > 'style_table1_header1')?


    The trivial answer is:

    alert(this.parentNode.className);

    But there may be more to your question than you've posted. You can
    also put a listener on the th of course, but I suspect you don't want
    to do that.


    --
    Rob
    RobG, Dec 20, 2009
    #2
    1. Advertising

  3. Rob, that's it!
    I haven't thought that it will be so easy. Great!

    Many thanks for your help.
    Stefan Mueller, Dec 20, 2009
    #3
  4. Stefan Mueller

    Evertjan. Guest

    RobG wrote on 20 dec 2009 in comp.lang.javascript:

    > On Dec 20, 9:08ÿam, Stefan Mueller <> wrote:
    >> I've several tables. The header row of each table looks like
    >> ÿ <th class = "style_table1_header1">
    >> ÿ ÿ <div class = "style_column1"
    >> ÿ ÿ ÿ onMouseover = "alert(this.className)">
    >> ÿ ÿ ÿ Header of Column 1 in Table 1
    >> ÿ ÿ </div>
    >> ÿ </th>
    >>
    >> ÿ <th class = "style_table1_header2">
    >> ÿ ÿ <div class = "style_column2"
    >> ÿ ÿ ÿ onMouseover = "alert(this.className)">
    >> ÿ ÿ ÿ Header of Column 2 in Table 1
    >> ÿ ÿ </div>
    >> ÿ </th>
    >>
    >> ÿ ...
    >>
    >> If you move the mouse pointer over the first header in table 1 'alert
    >> (this.className)' in the onMouseover event displays 'style_column1'.
    >> I there also a way to display the classname of <th> (in this example
    >> 'style_table1_header1')?

    >
    > The trivial answer is:
    >
    > alert(this.parentNode.className);
    >
    > But there may be more to your question than you've posted. You can
    > also put a listener on the th of course, but I suspect you don't want
    > to do that.
    >


    If the class name is realy specific to one element

    >> <th class = "style_table1_header1">


    better use an id

    <th id = "my_table1_header1">

    and

    #my_table1_header1 {..}



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Dec 20, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman

    className Attribute (UserControls)

    Charles A. Lackman, Jul 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    418
    Charles A. Lackman
    Jul 8, 2003
  2. Oliver S.

    classname::classname a type ?

    Oliver S., Sep 11, 2003, in forum: C++
    Replies:
    1
    Views:
    503
    White Wolf
    Sep 11, 2003
  3. Hongzheng Wang
    Replies:
    32
    Views:
    867
  4. mlt
    Replies:
    2
    Views:
    831
    Jean-Marc Bourguet
    Jan 31, 2009
  5. Ante Perkovic

    CSS: "tagname.classname" or ".classname"

    Ante Perkovic, Dec 22, 2003, in forum: Javascript
    Replies:
    2
    Views:
    103
Loading...

Share This Page