Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking Elements Exisitng Events i.e. onclick code

Status
Not open for further replies.

chant9

Technical User
Aug 30, 2005
7
Hi

I have been adding event listeners to forms and form elements like text boxes using addEventListener and attachEvent. However if I add an onclick it overwrites any existing onclick event.

Does anyone know how to check what events are currently attached to an element?

I currently have a function that does this for window onload events, it accesses window.onload then if this exists it strings together the existing code with the new code so it doesn't overwrite previous events. I haven't been able to do a similar thing for element events though.

Cheers
 
Hi

chant9 said:
I have been adding event listeners to forms and form elements like text boxes using addEventListener and attachEvent.
You mean like this ?
Code:
<html>
<head>
<script type="text/javascript">
window.onload=function() {
  var b=document.getElementById('but')
  b.addEventListener('click',function() { alert('first') },false)
  b.addEventListener('click',function() { alert('second') },false)
  b.addEventListener('click',function() { alert('third') },false)
}
</script>
</head>
<body>
<form action="">
<input type="button" id="but">
</form>
</body>
</html>
chant9 said:
However if I add an onclick it overwrites any existing onclick event.
You mean like what ? [tt]addEventListener[/tt] is designed to register event handlers without conflicting with the already registered ones. The above code works fine in standard compliant browsers.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top