Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:47:13+00:00 2026-05-23T09:47:13+00:00

I am attempting to style a hover state of a variable I have created.

  • 0

I am attempting to style a hover state of a variable I have created. I’m pretty new to javascript, so hopefully one of you can help me out.

here is the script:

controlDiv.style.padding = '5px';

var controlUI = document.createElement('DIV');
controlUI.style.height = '19px';
controlUI.style.backgroundColor = '#F9F9F9';
controlUI.style.background = 'linear-gradient(top, #ffffff 0%,#f3f3f3 50%,#ededed 51%,#ffffff 100%)';
controlUI.style.boxShadow = '2px 2px 2px 1px #999';
controlUI.style.borderRadius = '2px';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '1px';
controlUI.style.borderColor = '#9BADCF';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click Me';
controlDiv.appendChild(controlUI);

what I am wanting to do is to write script to set different style properties for the div created by the variable controlUI, when the mouse hovers over said div.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:47:14+00:00Added an answer on May 23, 2026 at 9:47 am

    Since you are working purely with JavaScript, instead of with CSS, you will need to do this the hard way, namely with events. With jQuery, it would be:

    $(controlUI).hover(
        function onMouseEnter() {
            this.style.backgroundColor = "blue";
        },
        function onMouseLeave() {
            this.style.backgroundColor = "#F9F9F9";
        }
    );
    

    Without jQuery, you would need to use DOM events, which is a pain because they are not cross-browser compatible with IE less than 9, as discussed extensively in this MDC article. The code ends up looking something like:

    var crossBrowserAEL = controlUI.addEventListener ? "addEventListener" : "attachEvent";
    
    controlUI[crossBrowserAEL]("mouseover", function () {
        controlUI.style.backgroundColor = "blue";
    });
    controlUI[crossBrowserAEL]("mouseout", function () {
        controlUI.style.backgroundColor = "#F9F9F9";
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to style a radio button and so I created a selector.
I am attempting to style some html that I do not have control over.
I'm attempting to re-style a vertical group of radio buttons, and the new theme
I have a WPF application, and I am attempting to style a TextBox using
I'm attempting to parse some Wiki-style markup using the Javascript Creole Wiki Markup Parser
I have a file containing perl-style regexs of the form /pattern/replace/ that I'm attempting
I am currently having problems with attempting to style the HTML rich text editor
I am attempting to compose a style sheet that, given an XML input (obviously)
I'm attempting to change the style of a button using the :checked and :unchecked
I'm attempting to save a c-style array of Vertex3D structs to an NSData object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.