473,386 Members | 1,652 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,386 software developers and data experts.

Using window.event

I have a set of HTML elements that I add an onclick event to at
runtime. All it does is get the contents of an element using
innerHTML.

It all works fine in Firefox, but I can't get it to work in IE. No
doubt I have a really simple error.... help!

window.event returns an object, but
window.event.toElement returns null.

A broken (in IE) sample snippet is below:

<html><head><title>Arrgghhh</title>
<script type="text/javascript">
ie = document.all;
function showTxt(e) {
var d = (ie) ? window.event.toElement.innerHTML :
e.target.innerHTML;
alert(d);
}
function addClick(){
document.getElementById('rob').onclick = showTxt;
}

</script>
</head>
<body onload="addClick();">
<p id="rob">here is robs text</p>
</body>
</html>
Jul 23 '05 #1
2 6077
On Wed, 10 Nov 2004 05:58:04 GMT, RobG <rg***@iinet.net.auau> wrote:

[snip]
window.event returns an object, but
window.event.toElement returns null.
It should. The toElement property, and its partner fromElement, are used
with the mouseout/over events to indicate where the mouse is going
to/coming from. The source of the event is given by srcElement.
<script type="text/javascript">
ie = document.all;
Umm...
function showTxt(e) {
var d = (ie) ? window.event.toElement.innerHTML :
e.target.innerHTML;


That isn't actually necessary.

var d = this.innerHTML;

should do. If you were to use the event object, the proper way would be
something like:

var d = (e ? e.target : window.event.srcElement).innerHTML;

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Michael Winter wrote:
[...]

That isn't actually necessary.

var d = this.innerHTML;

should do. If you were to use the event object, the proper way would be
something like:

var d = (e ? e.target : window.event.srcElement).innerHTML;


Thanks Michael, your first hint did the trick. I also appreciate your
abbreviated MS DOM test. I'd seen a similar version which would be (in
this case):

var d = (window.event ? window.event.srcElement:e.target).innerHTML;

But I think yours is better as it is more precise - it tests exactly
what I'm about to use - but I expect the result would be about as
consistent.

Rob.
Jul 23 '05 #3

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

Similar topics

5
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? ...
3
by: Søren M. Olesen | last post by:
Hi In IE there seem to be a global variable window.event, holding the current event....however this dowsn't work in FireFox... is there a similar way to get the current event?? TIA Søren
1
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur...
5
by: chad.a.morris | last post by:
Hi everyone, I didn't know how to sum this up very well for the title, but hopefully the person(s) will come along who can help. I'm trying to use the window.event.clientX value for...
9
by: mike | last post by:
I have this script executing <script> function mike_test(event) { x = window.event.clientX; alert(x); } </script> <iframe src="blank.html" id="my_iframe1"> </iframe>
1
by: den2005 | last post by:
Hi everybody, I am new in javascript. I am working on resizing a control like Image by dragging it to a desired size at runtime. Now, my onmouseover event is working ok where the cursor type...
6
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
5
by: anEchteTrilingue | last post by:
Hi everybody. Thank you for reading my post. I am having trouble getting "this" to work in all versions of IE (it's fine in Firefox, opera, konqueror, etc). What I would like to do is add an...
5
by: sdt76 | last post by:
Hi everybody! I have a question regarding IE. I have a client using a script (which I can not change as it is an affiliate program's script that I can not control) that creates a variable called...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.