Solved

document.onmouseup

Posted on 2009-07-03
2
629 Views
Last Modified: 2013-11-19
Hi

I am defining an event using javascript

like

document.onmouseup = mousehandler;

but now I want to define another event on onmouseup. How can I do that
0
Comment
Question by:KaranGupta
2 Comments
 
LVL 5

Accepted Solution

by:
Opalelement earned 500 total points
Comment Utility
Snippet:)
document.onmouseup = runMouseEvents;
 

function runMouseEvents()

{

    mousehandler();

    anotherEvent();

}
 

function mousehandler()

{

    // code

}
 

function anotherEvent()

{

    // other event code

}

Open in new window

0
 
LVL 3

Expert Comment

by:laneway
Comment Utility
You can also define an unlimited number of events like this:
<input id="btn" type="button" value="I have two events!" />

<script>

// define event functions

function event_one() { alert('one!'); }

function event_two() { alert('two!'); }

// get the button element that will trigger these events

var btn = document.getElementById('btn');

// attach the two events for internet explorer

if (btn.attachEvent) { 

  btn.attachEvent('onclick',event_one); 

  btn.attachEvent('onclick',event_two); 

}

// attach the two events for all other browsers

if (btn.addEventListener) { 

  btn.addEventListener('click',event_one,false); 

  btn.addEventListener('click',event_two,false); 

}

</script>

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now