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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:24:22+00:00 2026-05-14T21:24:22+00:00

I was doing some dynamic effect on DIV using JQuery when I found that

  • 0

I was doing some dynamic effect on DIV using JQuery when I found that
the returned value of this.id varied from function to function.

I got two sets of simple parent-child DIV tags like this:

        <DIV ID="row">
        <DIV ID="c1">              
        <Input type="radio" name="testing" id="testing" VALUE="1">testing1
        </DIV>
        </DIV> 
        <DIV ID="row">
        <DIV ID="c2">              
        <Input type="radio" name="testing" id="testing" VALUE="2">testing2
        </DIV>
        </DIV> 

Code 1.

$('#row DIV').mouseover(function(){ 
radio_btns.each(function() {
$('#row DIV).addClass('testing');  // worked
});
});

Code 2.

$('#row DIV').mouseover(function(){ 
var childDivID = this.id;
radio_btns.each(function() {
$('#'+childDivID).parent('DIV').addClass('testing');  // didn't work
});
});

I don’t understand why only the first code could work

and highlighted all the “row” DIV,
but the second code failed to do so?

  • 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-14T21:24:23+00:00Added an answer on May 14, 2026 at 9:24 pm

    First, you have the same ID multiple times, this will lead to all sorts of odd behavior since it’s invalid HTML.

    Once that’s corrected, for the second code example, you need an adjustment to highlight the current row on hover (note .row is now a class to eliminate the ID issue), like this:

    $('.row div').mouseover(function(){
        $('#'+this.id).parent('div').addClass('testing');
    });​
    

    However, there’s a better way to go about this since you already have the reference to the object, like this:

    $('.row div').mouseover(function(){
        $(this).addClass('testing');
    });​
    

    Generally speaking, I can’t think of a case where you’d want to use $("#"+this.id), if you have this, it should be $(this) to get the jQuery object you want.

    One more item, outside the question really, if you wanted a hover in this case, use .hover() and .toggleClass(), like this:

    $('.row div').hover(function(){
        $(this).toggleClass('testing');
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 439k
  • Answers 439k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer By default all programs use the C local (Because we… May 15, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer Take a look at inflector, a java project which lets… May 15, 2026 at 4:49 pm
  • Editorial Team
    Editorial Team added an answer I think you may be approaching this wrong. That's certainly… May 15, 2026 at 4:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.