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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:26:44+00:00 2026-05-30T10:26:44+00:00

$(.outerdiv .innerdiv).hover(function(){ var variable = $(this).index(); }); var variable = 3; $(span).html(variable); the original

  • 0
$(".outerdiv .innerdiv").hover(function(){
    var variable = $(this).index();
});
var variable = 3;
$("span").html(variable);

the original html of <span> is set as 3 using jquery but when hovering over an .innerdiv i want it to change to its index value by changing the variables outside the function to the index value of the specific .innerdiv that was hovered on. ​http://jsfiddle.net/eEUeT/9/

<div class="outerdiv">
    <div class="innerdiv">1</div>
    <div class="innerdiv">2</div>
    <div class="innerdiv">3</div>
    <div class="innerdiv">4</div>
    <div class="innerdiv">5</div>
</div>    
<span></span>​

I have tried http://jsfiddle.net/eEUeT/11/ this does not have a set orginal value of 3 however.


AND i understand by changing the html to <span>3</span> and using the jquery below will work but i would rather learn how to do it the way i asked

$(".outerdiv .innerdiv").hover(function(){
    var variable = $(this).index();
$("span").html(variable);
});
  • 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-30T10:26:45+00:00Added an answer on May 30, 2026 at 10:26 am

    If you want to manipulate an element, you have to select it… you can’t assign a value to a variable and expect the DOM element to update itself. As you stated though, it’s easily enough done like this:

    //set the initial HTML for the span element(s)
    var $span = $('span').html(3);
    
    $(".outerdiv .innerdiv").hover(function(){
    
        //update the span element(s) HTML to the index of the hovered-over `.innerdiv` element
        $span.html($(this).index());
    });
    

    ​

    This places the index of the hovered-over .innerdiv element as the HTML of any <span> elements.

    Here is a demo: http://jsfiddle.net/eEUeT/14/

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

Sidebar

Related Questions

Given a simplified document like this: <div id=outerDiv> <div id=innerDiv> <input id=theInput /> </div>
For example I have this code... <div id=outerdiv> <!--other tags--> <div class=innerdiv> <!--other tags-->
I have a page with two scroll bars. I am using the scrollTo jquery
Maybe this is asking to have my cake and eat it to, but I
I have a block of html like this. Judging by the background color of
Consider this bit of HTML & CSS: <html> <head> <title>Relative Positioning Resize Demo</title> <style>
I'm playing with the following application using the HTML Canvas: http://driz.co.uk/particles/ At the moment
I have the following html code: <div class=outer ui-draggable style=position: relative;> <div class=inner>Foo bar</div>
If the doctype declaration is <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 TRANSITIONAL//EN> what is
i set the opacity property of the outer div to the .5, and i

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.