473,480 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Box model issue?

Hi All!

In the code below, I want to add a handler to a *row* (eventually so I can
change the style of a row), but the event is being generated by the TD's it
seems - in Opera and IE. Is there another way to assign a handler, making
sure the event will come from the row and not a TD, or is this simply a box
model issue I cannot work around by assigning new handlers?

Any advice appreciated!

Rob
:)

<html>
<head>
<title>Hover on Row Test</title>
<script type="text/javascript">
function addEventHandler(element, eventName, functionName) {
if (element.attachEvent) {
element.attachEvent(eventName, functionName);
}
}
function info(event) {
infoElement = event.srcElement;
alert (infoElement.nodeName + " contains " + infoElement.innerHTML);
}
</script>
</head>
<body>
<table>
<tr><td>cell 1</td><td>cell 2</td></tr>
<tr><td>cell 1</td><td>cell 2</td></tr>
<tr><td>cell 1</td><td>cell 2</td></tr>
</table>
<script type="text/javascript">
elements = document.body.getElementsByTagName("tr");
for(var index = 0; index < elements.length; index++) {
addEventHandler(elements[index], "onmouseover", info);
}
</script>
</body>
</html>
Jul 23 '05 #1
3 1449
Robert Mark Bram wrote:
[...] I want to add a handler to a *row* [...] but the event is
being generated by the TD's
When an event is generated, it is /always/ targeted at the most deeply
nested element. So, if you rollover a cell, the cell will be the
target. To generate an event targeted at a row, the row itself (that
is, the region outside of any cells) must be the deepest element involved.

Once an event is generated, it will typically bubble-up to the root of
the document (not all events bubble), activating listeners as it goes.
[...] in Opera and IE.
In any user agent.
Is there another way to assign a handler, making sure the event
will come from the row and not a TD,
No.
or is this simply a box model issue [...]
It has nothing to do with the box model. That affects layout. This is
simply a standard behaviour of the event model.

[snip]
element.attachEvent(eventName, functionName);
Though the use of attachEvent does not, in itself, cause this issue
(as I said, the behaviour is standard), /not/ using it will allow you
to cope with the behaviour. You see, attachEvent is, in my opinion,
broken. Instead of setting the this operator to something sensible -
the element to which the listener is registered[1] - it is set to the
global object which is entirely useless.

If the IE event model provided a currentTarget equivalent (srcElement
is equivalent to target), the deficiencies of attachEvent could be
overlooked. However, this is not the case, so don't use it. If you
need to manage multiple listeners on the same element, either use
addEventListener or code which emulates it with the on<event>
properties. There have been several examples posted in this group's
archives.
function info(event) {
infoElement = event.srcElement;
alert (infoElement.nodeName + " contains "
+ infoElement.innerHTML);
}


Once you've moved away from attachEvent, you can change the above to

function info(e) {
alert(this.nodeName + ' contains ' + this.innerHTML);
}

Good luck,
Mike
[1] As you should know, this is what happens when an event listener is
added via HTML intrinsic event attributes, on<event> properties,
and the addEventListener method. The fact that attachEvent doesn't
follow this behaviour is the reason why I think it's broken.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Hi All,

Can anyone point me to an example of a 'home grown' way to introduce event
handling in the capturing phase as opposed to the bubbling phase for IE?

http://www.quirksmode.org/index.html..._advanced.html

Rob
:)
Jul 23 '05 #3
Robert Mark Bram napisał(a):
Hi All,

Can anyone point me to an example of a 'home grown' way to introduce event
handling in the capturing phase as opposed to the bubbling phase for IE?


Unless you implement your own javascript version for IE, its not possible.
--
tomasz cenian tcenian at wa dot home dot pl
:::: :: : : http://cenian.boo.pl : : :: ::::
Jul 23 '05 #4

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

Similar topics

7
8765
by: pysim | last post by:
Hi, I have a couple of general requests for pointers to python examples and design advice. I'm looking for examples of MVC-based GUI controls done in python (model-view-controller). Also,...
0
1495
by: Fritz Bosch | last post by:
We are in the process of refactoring our GUI-based test application for radio equipment and are rewriting a significant part in Python. The new architecture will substantially be based on the...
1
3324
by: Abhijit | last post by:
I am working in a data warehousing environment which gets sourced from Oracle ERP (AR/GL/AP). The dimensional entities associated with incoming data are GL Code (e.g. 110), Department (e.g. 1050),...
19
2326
by: Steve Jorgensen | last post by:
I've run across this issue several times of late, and I've never come up with a satisfactory answer to the best way to handle this schema issue. You have a large section of schema in which a...
5
2112
by: Kevin C | last post by:
I was curious to know what some developers out in the industry are doing when it comes to exposing Data access logic, specifically persistence. This is assuming that your not using an O/R framework...
1
3320
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
12
1468
by: Mike Gaab | last post by:
Hi, A newcomer to .Net (I've held out as long as I can.). I am using VS.Net 2003. I am writing some web apps and I am confronted with the usual issues that one faces when coming from a Windows,...
50
5989
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
9
1429
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - What is the document object model? ----------------------------------------------------------------------- ...
0
7048
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
7050
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
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6966
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...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.