How to read the classname of the table header

S

Stefan Mueller

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')?
 
R

RobG

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.
 
S

Stefan Mueller

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

Many thanks for your help.
 
E

Evertjan.

RobG wrote on 20 dec 2009 in comp.lang.javascript:
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

better use an id

<th id = "my_table1_header1">

and

#my_table1_header1 {..}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top