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 7078271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:31:36+00:00 2026-05-28T06:31:36+00:00

i have 3 divs with the same class. <div id=qq1 class=cl>sentence</div> <div id=qq2 class=cl>sentence</div>

  • 0

i have 3 divs with the same class.

<div id="qq1" class="cl">sentence</div>
<div id="qq2" class="cl">sentence</div>
<div id="qq3" class="cl">sentence</div>

well i’d like to know how can i write correct code for entering mouse calling with one function for 3 divs (calling cl class) and returning the correct id for change css.for ex:

<script>
$('.cl').live('mouseenter', function() {
    var currentId = $(this).attr('id');
    $('currentId').css("background-color", "#99cc33");
    $('currentId').css("color", "white");
});
$('.cl').live('mouseleave', function() {
    var currentId = $(this).attr('id');
    $('currentId').css("background-color", "white");
    $('currentId').css("color", "#404040");
});
</script>

But there’s something wrong ’cause it doesn’t work

  • 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-28T06:31:37+00:00Added an answer on May 28, 2026 at 6:31 am

    You don’t ever use the currentId variable, instead you try to use a string that contains the letters c, u, r, etc., 'currentId'.

    To make it work with that variable you would need to say $('#' + currentId).css() – so if, e.g., currentId is 'qq1' then in effect you would be saying $('#qq1').css().

    However you don’t need the id at all because you can simply use $(this):

    $('.cl').live('mouseenter', function() {
        $(this).css({"background-color" : "#99cc33",
                     "color" : "white"});
    });
    
    $('.cl').live('mouseleave', function() {
        $(this).css("background-color", "white");
        $(this).css("color", "#404040");
    });
    

    Within a jQuery event handler this refers to the DOM element itself, while $(this) creates a jQuery object for that element so that you can call jQuery methods on it. Note that the .css() method accepts a map of multiple properties so you can set them all with a single call – I’ve shown that syntax in the mouseenter but not the mouseleave so that you can compare.

    (Note: not related at all to your question, but if you are using jQuery 1.7+ you should stop using .live() because it has been deprecated in favour of .on() – there are instructions on the .live() doco page for how to convert your code. If you are using < 1.7 but > 1.4.2 you should use .delegate().)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 1 div that will contain 3-5 divs with the same class. Below
I have multiple divs in my body which need the same style: <div class=box></div>
I have three DIVs, something like this: <div id=header> ... </div> <div id=content> <div
I have 30 divs with the same class on the same page. When i'm
I have a set of divs with the same class. I need to give
I have a series of divs of the same class; some with title attributes
I have a series of divs: <div class=some_class active>Some Content</div> <div class=some_class>Different Content</div> <div
I have 4 DIVs with the same class, .category-container and basically what I need
I have a few divs with the same class. The divs are generated dynamically,
I have a collection of divs with the same class at various positions on

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.