Solved

document.onmouseup

Posted on 2009-07-03
2
636 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
ID: 24772580
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
ID: 24773625
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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…

820 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