473,465 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Custom Event in JavaScript

Jezternz
145 New Member
Okay.
I basicly want an event like
onElementClose
Basicly will trigger a function when another div/block/element comes within a certain area around it (say 5px for eg).

I am sure custom events are possible, I have seen strange examples around.
So unless you are 100% certain this is impossible, please dont say its impossible.

a setInterval that checks if there is an element around it every so long is not acceptable. as there will be hundreds of elements using this event.

If i havent explained this clearly enough please ask

Thanks, Josh.
May 29 '08 #1
11 1706
acoder
16,027 Recognized Expert Moderator MVP
How will the elements come close, i.e. will they be moved from their original position, or will new elements be created which could potentially come close to an already existing element?
May 29 '08 #2
Jezternz
145 New Member
moved from their origonal position, the elements will all be position: absolute.
So will be moved by an x and y axis using "left" and "top"
May 29 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
If you're YUI or Dojo, they have support for custom events, see, for example, YUI Custom Events. You might find this article useful too.
May 29 '08 #4
rnd me
427 Recognized Expert Contributor
use the mutation dom events
May 29 '08 #5
Jezternz
145 New Member
this looks complicated, thanks guys, ill have a read.
May 30 '08 #6
Jezternz
145 New Member
What d you mean by mutation events? also: I would prefer to avoid third party scripts/libraries if possible.
addEventListener <- I dont entirely understand what they mean about this function what exactly does it do? If anyone could help me with any of this, or even better start me off, would be mnuch apreciated.

cheers, Josh
May 30 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
What d you mean by mutation events?...
addEventListener <- I dont entirely understand what they mean about this function what exactly does it do?
Mutation events notify of changes to the document structure. However, these are not well supported. Firefox, Safari and Opera support some of them.

addEventListener is a more advanced event model method. Unfortunately, it's not supported by IE (as ever). Fortunately, IE has its own version. See this link for more information.
May 30 '08 #8
Jezternz
145 New Member
I read that, but I dont really see the difference between:

element.addEventListener('click',doSomething,false )
element.onclick = doSomething;

I understand eventlistener can be used multiple times, but apart from that are they exactly the same?

cheers Josh
Jun 3 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
Not quite, see Why use addEventListener?.
Jun 3 '08 #10
Jezternz
145 New Member
wait so if im understanding this correctly.
This wont bubble:
element.addEventListener('click',doSomething,false );
This will buble:
element.onclick = doSomething;

meaning the first one will only activate if it is clicked (and wont activate if its children are clicked, where the second one would)

Thanks again acoder, Josh
Jun 4 '08 #11
acoder
16,027 Recognized Expert Moderator MVP
No, if you have false as the third argument, it will bubble. When it's true, it's in the capturing phase (parent fires first, then child). If you want to stop bubbling/capturing, use stopPropagation() (W3C) and cancelBubble=true (Microsoft). See this link for a good explanation of this concept.
Jun 4 '08 #12

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

Similar topics

2
by: Hawk | last post by:
I have a custom menu control that I am creating using C#. I am rendering HTML from a StringBuilder in my control to add the needed JavaScript to the HTML output. I need to have the JavaScript...
0
by: paul.phillips | last post by:
Hi, I am a problem: I have a custom control called DataView that holds a DataGrid object. The DataGrid has an event attached (PageIndexChanged) now the problem is that the event is not being...
1
by: neil S via DotNetMonster.com | last post by:
I have a custom control with a textbox and dropdown list. The dropdown list is hidden and acts as a data source for the textbox. When the user enters text in the textbox, an onKeyup event is...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
1
by: ThunderMusic | last post by:
Hi, I'm making a Custom Web Control and I'm wondering how I can insert Javascript code into the head part of the document from within my web control... I lloked at the methods of the...
1
by: centur | last post by:
Hello. I created simple asp.net application to search message history over Office Live Communicator conversations. I complete quite all job but stick with one thing - I have autosuggest box...
1
by: rn5a | last post by:
I have created a custom control button which when clicked displays a message in the JavaScript alert dialog. I could successfully compile the VB class file into a DLL & also could add it to the...
3
by: Tomasz J | last post by:
Hello Developers, How do create a custom WebControl (not UserControl), exposing OnClick event? I reviewed countless examples found by Google, but came across nothing helpful. Below I attach...
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,...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.