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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:33:09+00:00 2026-05-24T19:33:09+00:00

I have no idea if I just found a potential jQuery bug, but check

  • 0

I have no idea if I just found a potential jQuery bug, but check out the following case.

If I’m dynamically changing a data-ajax-link attribute and then try to get it’s value with $('something').data('ajax-link'); the value that’s retrieved is still the old one before changing it dynamically.

Here is the example. It’s a custom dropDown that sets the clicked option to the first child of the ul. The name of the element as well as the data-ajax-link of the first-child is updated with the values of the clicked option … http://jsfiddle.net/RLF3W/1/

$('.select .option').live('click', function (e) {
    e.stopPropagation();
        $(".select .option:not('.darr')").hide();
        selectedOption = $(this).parents("div.select").find(".option:first");

        $(this).siblings().show();
        selectedOption.text($(this).text()).attr('data-ajax-link', $(this).data('ajax-link'));
});

$('.select .option:not(".darr")').live('click', function () {
    $(this).parents("div.select").find(".option:not('.darr')").hide();
});

$(window).click(function() {
    $(".select .option:not('.darr')").hide();
});


$('a#tester').live('click', function(e) {
    e.preventDefault();

    //var sort = $('#sortb .darr').attr('data-ajax-link');
    var sort = $('#sort .darr').data('ajax-link');

    $('#output').text(sort)

});

In my example you can see that after selecting a different option in the dropdown and then hit the test link the value of the data-ajax-link is still the original value, even though it’s actually changed if the element is inspected. If I use .attr('data-ajax-link') to get the updated value it works fine.

Am I wrong here and I’m doing something wrong or is this a bug?

  • 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-24T19:33:10+00:00Added an answer on May 24, 2026 at 7:33 pm

    You’re setting it using .attr(), but getting it using .data().

    I’m pretty sure that when getting via .data(), it first looks at its data in jQuery.cache to see if the property exists. Then if not, it looks for an attribute.

    You should just send it via the data- attribute but use .data() to get and set.

    Change this:

    selectedOption.text($(this).text()).attr('data-ajax-link', $(this).data('ajax-link'));
    

    to this:

      // Use .data()----------------------v
    selectedOption.text($(this).text()).data('ajax-link', $(this).data('ajax-link'));
    

    Example: http://jsfiddle.net/RLF3W/5/

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

Sidebar

Related Questions

I have absolutely no idea how to do this, so I'm just gonna go
Okay, this is just a crazy idea I have. Stack Overflow looks very structured
Any body have idea how to put controls dynamically in asp.net 3.5 ? if
I have an idea for how to solve this problem, but I wanted to
anyone have an idea to make a marquee effect just like twitter ? its
Anyone have a idea about solve memory leak issues i have found one memory
Um, probably a really simple question, but I just noticed that I have no
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)
I have no idea why this behaviour is occuring, but I'll try and explain...
I have the same problem as Simon in this post . He found out

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.