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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:02:57+00:00 2026-06-13T19:02:57+00:00

Now, bear in mind I’m just trying to ensure that the code works by

  • 0

Now, bear in mind I’m just trying to ensure that the code works by consuming the ready event here. I just want to make sure that the data I expect is getting pulled by jQuery. I’ve also tried the load event.

In the end I’d want to use the load or ready event to set the image initially and then of course use the hover event to change that image on hover.

I’ve tried a lot of the answers here on SO and just can’t seem to get this working, so hopefully y’all can help me.

JavaScript:

$(document).ready(function () {
    $("#submenumain-link").ready(function () {
        alert($(this).data()["selectedimage"]);
        alert($(this).data()["hoverimage"]);
    });

    $("#submenumain-link").hover(function () {
        alert($(this).data("selectedimage"));
        alert($(this).data("hoverimage"));
    });
});

HTML:

<li id="submenumain-link"
    data-selectedimage="some-image.png"
    data-hoverimage="some-other-image.png">

But for whatever reason the alert messages just state undefined. Am I missing something here?

EDIT

Note that if I place those same alert statements in the hover, it works as expected. What event could I use to do the initialization?

  • 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-06-13T19:02:58+00:00Added an answer on June 13, 2026 at 7:02 pm

    The real problem is that ready should not be used in this way. The ready event should only be used with making sure the DOM is ready – http://api.jquery.com/ready/

    So technically, inside of document.ready, all of the DOM is ready and should be available for these kinds of things. Inside of document.ready, the value of this refers to the document element, so you need to actually grab the li element. Your code should be something like this:

    $(document).ready(function () {
        var li = $("#submenumain-link");
        alert(li.data()["selectedimage"]);  // or li.data("selectedimage")
    
        li.hover(function () {
            //alert($(this).data("selectedimage"));
            //alert($(this).data("hoverimage"));
        });
    });
    

    http://jsfiddle.net/XN2LV/

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

Sidebar

Related Questions

I'm just fiddling around with user scripts in chrome right now, so please bear
jsfiddle demo Bear with me, total newb here. I'm trying to make a simple
I'm new to web development so bear that in mind. I'm creating my first
bear with me, I've been using wxPython for all of one day now. Short
now i'm working on a project for creating audio unit instrument that provide the
Now facebook require to have these options when you want to use bulit-in actions
Now I try to developing an application related to Image processing, for that I
I'm trying to build my own prediction market, and I'm thinking about algorithms. That
English isnt my native language so bear with me. Im trying to make it
Now I'm new to the WINSOCKs, and not super fluent in C++, so bear

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.