Jquery data function remove null from start of string
I have something like this:
<input id="zip_code" type="text" value="" data-existing-value="09458" name="zip_code"/>
I am trying to get the existing zip code value from a data parameter using:
$("#zip_code).val($('#zip_code').data('existing-value'));
And for some reason the null is removed ... and all I get for the textbox value is "9458" with no leading zero ...
How can I store zero?
+3
Tamik Soziev
source
to share
2 answers
Try it . attr () instead of . data ()
$("#zip_code).attr('data-existing-value');
+3
Fabian
source
to share
You must use attr('data-existing-value')
.
http://bugs.jquery.com/ticket/7579
+2
Daniel A. White
source
to share