I have a div like this :
<td id="length" data-length=<?php echo $length;?> >
And I want to get the value of my php variable ($length) in a jquery script.
After that I have to format it to replace the comma with point.
With this snippet :
var $length = jQuery(this).find("#length");
console.log($length.data('length'));
I see read my variable in the console
but when I want to format it to replace the comma with a point like this :
console.log(parseFloat($length.val().replace(",", ".")));
I get NaN
Please help to solve that problem !
Your missing the quotes around the value of data-length. Correct your HTML markup like this:
Next, you do not want
val()you wantdata('length')