Class of js?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Class of js?

Post by Todd_Z »

Can I assign the same onMouseOver, onMouseOut events to a group of <td>'s?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

assign the events to them in a loop...
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

Ok, to achieve that, I would like to figure out how to iterate over all the td's in a div.

Code: Select all

<div id=&quote;nav&quote;>
 <table width=&quote;100%&quote; cellpadding=&quote;2&quote; cellspacing=&quote;0&quote;>
  <tr>
   <td onclick=&quote;window.location='?page=Home';&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Home</td>
   <td onclick=&quote;buttonClick(event, 1);&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Reviews</td>
   <td onclick=&quote;window.location='?page=Recent Releases';&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Recent Releases</td>
   <td onclick=&quote;window.location='?page=Coming Soon';&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Coming Soon</td>
   <td onclick=&quote;window.location='?page=Cast And Crew';&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Cast And Crew</td>
   <td onclick=&quote;buttonClick(event, 2);&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Links</td>
   <td onclick=&quote;buttonClick(event, 3);&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Media</td>
   <td onclick=&quote;window.location='?page=About';&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>About</td>
   <td onclick=&quote;window.location='?page=Contact';&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Contact</td>
   <td onclick=&quote;buttonClick(event, 4);&quote; onmouseover=&quote;this.className='selected';&quote; onmouseout=&quote;this.className='';&quote;>Search</td>
  </tr>
 </table>
</div>
So i'd like to iterate all of the tds in the div marked "nav" and then assign onmouseover="this.className='selected';" onmouseout="this.className='';" to each - How could i do this?
Post Reply