Change onmouseout method with onclick

Posted on 2005-03-29
Medium Priority
Last Modified: 2012-06-21
Hey all,

I need to change the onmouseout function of an element when I click on it.  For example, I want it to call one JavaScript function when I mouse out of an image until I click on that image, after which I want to call another function when I mouse out of it.  I thought that I might be able to use the addEventHandler() method, but can't seem to get it to work.  Any ideas?
Question by:jonbigelow
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 19

Accepted Solution

dakyd earned 500 total points
ID: 13657713
Here's an example, though I think you'll probably want something a bit more complicated than this.  It starts out with a mouseout that turns the div yellow, but once you click on it, the mouseout turns the div red.  Hope that helps, but if you need something more suited to what you want, let us know.

<div onclick="this.onmouseout = function() {this.style.backgroundColor = 'red';};" onmouseover="this.style.backgroundColor = 'green';" onmouseout="this.style.backgroundColor = 'yellow';">TEST DIV</div>

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses

764 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