Bug Tracker

Ticket #6304 (closed bug: fixed)

Opened 5 years ago

Last modified 4 years ago

calling $(...).data() changes behaviour of $(...).data('nosuchkey')

Reported by: tgdavies2 Owned by:
Priority: undecided Milestone: 1.4.3
Component: data Version: 1.4.2
Keywords: Cc:
Blocking: Blocked by:

Description

If you call ...data('foo') you get a result of null, but if you then call ...data() followed by ...data('foo') the result is undefined:

<html> <head>

<script type="text/javascript" src=" http://code.jquery.com/jquery-1.4.2.js"></script> <script type="text/javascript"> $(document).ready(function() {

$("#firstvalue").html(typeof $("#foo").data('bar')); var ignored = $("#foo").data(); $("#secondvalue").html(typeof $("#foo").data('bar'));

}); </script>

</head> <body> <div id="foo">Div named foo</div> <div>First value of $("#foo").data('bar'):<span id="firstvalue"/></div> <div>Second value of $("#foo").data('bar'):<span id="secondvalue"/></div> </body> </html>

Change History

comment:1 Changed 4 years ago by john

  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to fixed

I wasn't able to replicate this (namely the result of null) so I think this is fixed on our end. I added some extra tests:  http://github.com/jquery/jquery/commit/515efbdc7119aa79de710144effe18413d4cb14a

Note: See TracTickets for help on using tickets.