473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Setting onMouseOut attribute within JavaScript

Howdy All!

I am really stuck with this one - I want to completely create a table
within JavaScript and insert it into the document, with onMouseOut and
onMouseOver handlers in the table rows.

Below is a sample of the code I have created. It all works in Netscape
7.1, but in IE 6 it shows the table but the handlers do not run. I can
prove the handlers are even there (see the commented out alert command
in the code) so why aren't they being called??

Any help on this problem would be most appreciated!

Rob
:)
<html><head><title>Untitled Document</title>
<script type="text/javascript" language="JavaScript">
function setAttribute (object, attributeName, attributeValue)
{
var attributeNode = document.createAttribute (attributeName);
attributeNode.value = attributeValue;
object.setAttributeNode (attributeNode);
} // end setAttribute method
function writeTable()
{
var menuTable = document.createElement ("table");
var tableBody = document.createElement ("tbody");
menuTable.appendChild (tableBody);
menuTable.setAttribute ("width", "100%");
menuTable.setAttribute ("border", "0");
menuTable.setAttribute ("cellPadding", "0");
menuTable.setAttribute ("cellSpacing", "0");

// Create a table row for each node in menu array.
for (var index = 0; index < 10; index ++)
{
var tableRow = document.createElement ("tr");
setAttribute (tableRow, "onMouseOut", "alert ('mouse out');");
setAttribute (tableRow, "onMouseOver", "alert ('mouse over');");

// alert (tableRow.onmouseout);

var tableCell = document.createElement ("td");
var cellText = document.createTextNode ("Test Row");
tableCell.appendChild (cellText);
tableRow.appendChild (tableCell);
tableBody.appendChild (tableRow);
} // end for
document.getElementById ("mainMenuContainer").appendChild
(menuTable);
}
</script></head>
<body onLoad="writeTable();">
<div id="mainMenuContainer"></div>
</body>
</html>
Jul 20 '05 #1
1 11152
DU
re********@optushome.com.au wrote:
Howdy All!

I am really stuck with this one - I want to completely create a table
within JavaScript and insert it into the document, with onMouseOut and
onMouseOver handlers in the table rows.

Below is a sample of the code I have created. It all works in Netscape
7.1, but in IE 6 it shows the table but the handlers do not run. I can
prove the handlers are even there (see the commented out alert command
in the code) so why aren't they being called??

Any help on this problem would be most appreciated!

Rob
:)
<html>
Using a full doctype declaration will trigger MSIE 6 for Windows into
standards compliant rendering mode. It's always preferable, furthermore
if you're using DOM 2 HTML interface methods.

<head><title>Untitled Document</title> <script type="text/javascript" language="JavaScript">
function setAttribute (object, attributeName, attributeValue)
Very bad function name: there is a DOM 2 Core Interface method with such
name. You're making your code a lot harder to figure out here.

http://www.w3.org/TR/2000/REC-DOM-Le...tml#ID-F68F082
{
var attributeNode = document.createAttribute (attributeName);
attributeNode.value = attributeValue;
objRef.setAttribute(name, value);
is faster and more to the point, as explained by the specs.
object.setAttributeNode (attributeNode);
the setAttributeNode method does not work well on many browsers.
} // end setAttribute method
function writeTable()
{
var menuTable = document.createElement ("table");
var tableBody = document.createElement ("tbody");
menuTable.appendChild (tableBody);
You should define the tbody element, then assign its properties and
attributes before appending it to the menuTable element. The rest of
your DOM nodes declaration, construction follows that logic.
menuTable.setAttribute ("width", "100%");
menuTable.width = "100%";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-77447361
And even here, this is not useful really as the default width value of a
table is always 100% on all browsers.
menuTable.setAttribute ("border", "0");
menuTable.border = "0";
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-50969400
[
General rule: don't use setAttribute() when a better way of setting the
attribute is available (ie. x.style.display="none" instead of
x.setAttribute('style,'display: none')).
http://www.xs4all.nl/~ppk/js/w3c_core.html#attributes
]

menuTable.setAttribute ("cellPadding", "0");
menuTable.setAttribute ("cellSpacing", "0");

menuTable.cellPadding = "0";
menuTable.cellSpacing = "0";
// Create a table row for each node in menu array.
for (var index = 0; index < 10; index ++)
{
var tableRow = document.createElement ("tr");
insertRow is another alternative, also supported by MSIE 6 for Windows,
NS 6.2+ (and Mozilla-based browsers) and Opera 7.x
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-39872903
setAttribute (tableRow, "onMouseOut", "alert ('mouse out');");
tableRow.setAttribute("onmouseout", "alert('mouse out')");
will work in Mozilla 1.4 and Opera 7.20. It is known that MSIE 6 for
windows does not support changing, modifying, setting event attributes.
I remember answering a post on this issue in, IIRC, this newsgroup.
setAttribute (tableRow, "onMouseOver", "alert ('mouse over');");

// alert (tableRow.onmouseout);

var tableCell = document.createElement ("td");
insertCell is also a method supported by Mozilla-based browers, Opera
7.x and MSIE 6. I personally prefer it over createElement because it's a
bit more faster. insertCell creates and append the node with 1 line of code.
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-68927016
var cellText = document.createTextNode ("Test Row");
tableCell.appendChild (cellText);
or
tableCell.appendChild(document.createTextNode ("Test Row"));
tableRow.appendChild (tableCell);
tableBody.appendChild (tableRow);
} // end for
document.getElementById ("mainMenuContainer").appendChild
(menuTable);
}
</script></head>
<body onLoad="writeTable();">
<div id="mainMenuContainer"></div>
</body>
</html>

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin Ly | last post by:
Consider the test case below. The onmouseout event does NOT fire when my mouse/cusor is moved off the left side of the browser. It does if it is moved off the top, bottom, and the right side that...
12
by: Epetruk | last post by:
Hi all, I want a page where the contents of a table cell are replaced with an image when the mouse moves over the cell, and the text is restored when the mouse moves out. Here's the html for the...
3
by: Tor Inge Rislaa | last post by:
Hi, I control the style of a button like the code below Private Sub Change_Color() Button1.Style("BACKGROUND-COLOR") = "#CEB57B" Button1.Style("COLOR") = "White" End Sub How can I do the...
3
by: Rob Roberts | last post by:
I'm using .NET 2.0 and C# on a web site, and I'm trying to use the onmouseover and onmouseout events to do a rollover effect on an asp.net button. I've tried manually adding the events to the...
2
by: Daz | last post by:
Hi everyone. I think my problem is a simple one, but I am completely baffled as to how to pull it off. I have a piece of code like so... document.write( "<img id=\"slideshow_toggle\"...
2
by: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given...
4
by: moltendorf | last post by:
Hey, I've got another issue, although my last one was never worked through... I'm pretty sure this is easy to solve. I've got a little javascript code and I would like to have it be able to fire an...
1
by: RobertTheProgrammer | last post by:
Hi all, I have a perplexing problem here. I've developed some software using ASP.NET with C# in the code behind. I've been setting the "window.defaultStatus" in the code behind to send messages...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.