Solved

onClick event for a <tr> table element in Firefox/Mozilla .... not working. IE does.

Posted on 2004-09-30
3
3,238 Views
Last Modified: 2012-08-13
As far as i know, firefox/mozilla (in contrary to IE) does not support onClick event on the <tr> table element, so the only way to simulate it is that each row of table acts as one <div>, which reacts to onClick...  It's fairly complicated to implement, is there any better solution to this?

Greetings,
Marko
0
Comment
Question by:pyc42
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 250 total points
ID: 12189333
This works for me in Mozilla1.7.2:

<html>
<body>
<table>
<tr onClick="alert('Hello')"><td>Click me</td></tr>
</table>
</body>
</html>

0
 

Author Comment

by:pyc42
ID: 12189456
okay you're right, and i really misunderstood some piece of code i had recently (not havin' it right now, but i'll upload it asap)... it's actually a part of the question...
0
 

Author Comment

by:pyc42
ID: 12190261
<html>
<head>
<script type="text/javascript">
function swapBG(obj)
{
var colour;
colour=(obj.style.background==obj.id) ? "green" : obj.id;
obj.style.background=colour;
}
</script>
</head>

<body>
<table cellspacing="1" border="1">
<tr style="background:red;" id="red" onclick="swapBG(this);">
<td width="200" height="20"></td><td width="200"></td><td width="200"></td>
</tr>
<tr style="background:orange;" id="orange" onclick="swapBG(this)">
<td width="200" height="20"></td><td width="200"></td><td width="200"></td>
</tr>
<tr style="background:yellow;" id="yellow" onclick="swapBG(this)">
<td width="200" height="20"></td><td width="200"></td><td width="200"></td>
</tr>
</table>
</body>
</html>


...... colour=(obj.style.background==obj.id) ? "green" : obj.id;     this line is not working in Firefox, that was my problem.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now