473,651 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using "this" and "window.event.s rcElement" in IE

1 New Member
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 event listener to an element to change its border on mouseover and mouseout. I don't want to use CSS to do this (long story).

The problem is that "this" does not work at all in IE for me. I tried to do a try/catch statement and use "window.event.s rcElement", but this causes all of the child elements to fire the function as well, which is obviously not desireable (I don't want the children to have borders).

So I have 2 questions:
1. Do I have a syntax error that is preventing "this" from working in IE or does IE just not support it?
2. How do I get the function to fire on the parent element only and not the children?


This is what my html looks like:
[HTML]<div class="borderCh anges">
<img src="path/to/img" alt="img description" />
<a href="link">Lin k Text</a>
<div>Some more Text</div>
</div>[/HTML]
This is the javascript that I am attaching to the div:

Expand|Select|Wrap|Line Numbers
  1. function linkHover (){
  2.   try {this.style.border = "2px solid green";}
  3.     catch (err){window.event.srcElement.style.border = "2px solid green";}
  4.   try {this.style.padding = "4px";}
  5.     catch (err){window.event.srcElement.style.padding = "4px";}
  6. }
  7. function linkOut (){
  8.   try {x=this.style.border = "1px solid black";}
  9.     catch (err){event.srcElement.style.border = "1px solid black";}
  10.   try {x=this.style.padding = "5px";}
  11.     catch (err){event.srcElement.style.padding = "5px";}
  12. }
Again, thank you to everybody.
Nov 10 '07 #1
5 6482
gits
5,390 Recognized Expert Moderator Expert
hi ...

welcome to TSDN ...

how do you attach the handlers to the div?

kind regards
Nov 11 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
Unfortunately, this is an important drawback of IE's event model. You can never know which element is currently handling the event. See link (Problems of the Microsoft model).
Nov 11 '07 #3
gits
5,390 Recognized Expert Moderator Expert
Unfortunately, this is an important drawback of IE's event model. You can never know which element is currently handling the event. See link (Problems of the Microsoft model).
hmmm ... good link :) ... so for the original problem in IE you have to ask for the srcElement and in case you get one that you don't want to handle you may climb up the dom and use the parentNode or something like this ...
Nov 11 '07 #4
Dasty
101 Recognized Expert New Member
Unfortunately, this is an important drawback of IE's event model. You can never know which element is currently handling the event. See link (Problems of the Microsoft model).
This is easy avoidable. Just dont assign same function for 2 (more) nested elements if you want to handle event differently (makes sense to me).

And to op: nobody can help you without knowing how you attach and to what elements you attack your event-handlers.
Nov 11 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
This is easy avoidable. Just dont assign same function for 2 (more) nested elements if you want to handle event differently (makes sense to me).
Sometimes you can't avoid it and might need that information. I remember seeing some code that deals with (I think) this problem in IE. If I find it, I'll post the code or a link to it.
Nov 12 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3890
by: Robert Oschler | last post by:
I've successfully attached to the "onclick" and several other events using AttachEvent(). But when I try to attach to the "onbeforeunload" event it doesn't work (the handler I've assigned is never called). Is there something different about this event? Is there another way to attach to this event that would work, other than manually filling in the <BODY> tag with an 'onunloadbefore' assignment? thx
2
2257
by: Franklin P Patchey | last post by:
<P><A style="COLOR: rgb(0,0,0); FONT-SIZE: 80%; FONT-FAMILY: 'Comic Sans MS', cursive; TEXT- ALIGN: left" href="javascript:self.close();"><FONT size=4><STRONG>Close this window!</STRONG></FONT></A></P>
1
1769
by: charliewest | last post by:
I would like to implement the following functionality: When a user taps a (child) treeNode, an event fires which allows me to get the selected treeNode's TAG object, determine it's values, and then load a new form based on those values... Intellisense shows the "Click" event, however, this does nothing. (I assume it's not supported in .Net CF?) I see via Design Mode in VS 2003 that the only feasible event is "AfterSelected". This,...
3
3979
by: JohnR | last post by:
I have a form with a number of text boxes, comboboxes etc. What I would like to do is create an event handler for the "mouseenter" event for each of the controls whereby I display information about the control they just entered (sort of like an extended tooltip). Now, I can certainly create a separate mouseenter event for each control (too much work, and not very clever), but what I would like to do is somehow create one event that would...
22
130150
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the document and closes it with the following code: <body onload="window.print(); window.close();"> This works correctly (or at least the way I expect it to work under MS Internet Explorer, but it cuases Netscape to "crash"
2
1527
by: Kevin Frey | last post by:
We have a web application that, for the purposes of reporting, launches a new window to display the contents of the report in (PDF format). This is implemented using a custom IHttpHandler implementation in our project. The report is launched by a standard hyperlink with a target="blank" to force the new window. The one problem I have noticed is that if the user leaves the "launcher" page open a long time, the web server will invariably...
2
1556
by: Bryan | last post by:
Hello all, Can anyone explain when one should use the "document" object and when one should use the "this" object? Also, is the "self" object the same as the "document" or "this" object?
2
7707
by: bay_dar | last post by:
Hi, I have an internal ASP.NET application that I'm are using to send e-mails out based on a single milepost or milepost range entered. I'm trying to do two things when a user clicks on the submit button to submit a form that contains one or two Mileposts: 1) If a Milepost range larger than 5 miles is entered, I would like to pop up a confirmation box to confirm the range.
0
967
by: jgnprt | last post by:
I am converting a doc file to pdf file programmatically using Vb 6.0 but as the program runs it is showing the Save as window .........Can anybody help me in suppresiing this window. I want to save the pdf file with a predefined path and a predefined name through code itself.
24
8203
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and seems to have a (tiny) amount overhead since window itself points to the global object, hence, a circular reference. (From everything I am reading, window is just a REFERENCE back to the global object, as opposed to a separate object.)
0
8807
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8466
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7299
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5615
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.