Bug Tracker

Modify

Ticket #10106 (closed bug: duplicate)

Opened 21 months ago

Last modified 21 months ago

.data() as string

Reported by: Aske Owned by:
Priority: low Milestone: None
Component: data Version: 1.6.2
Keywords: Cc:
Blocking: Blocked by:

Description

When i store a value like "001" into the data attribute and retrieve it with .data() i get "1" returned. This should be "001" and not parsed as an int.

Example here:  http://jsfiddle.net/Aske/WzFS4/

Change History

comment:1 Changed 21 months ago by addyosmani

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to data

Confirmed. I believe we're using parseFloat(n) as opposed to parseInt(n), but it's essentially causing the same issue regardless. One possible workaround for now would be storing 001 as a single-quoted string within your data-value, however this isn't ideal:  http://jsfiddle.net/WzFS4/2/.

comment:2 Changed 21 months ago by timmywil

  • Status changed from open to closed
  • Resolution set to duplicate

This is expected behavior and a feature of the .data() method. It is explained in the docs: "Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null) otherwise it is left as a string. To retrieve the value's attribute as a string without any attempt to convert it, use the attr() method."

comment:3 Changed 21 months ago by timmywil

Duplicate of #10042.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.