javascript - Division produces NaN -


i'm trying divide variable number 100 , nan. i'm new jquery, can me understand i'm doing wrong?

$.each(data.products, function (i, data) {      var div_data = "<p>" + data.title + "<br/>" + data.description + "</p>";      div_data += '<img src="' + data.imageurl + '" title="loading..." alt="loading...">';     div_data += '<p><a href="' + data.url + '">buy</a></p>';      $(div_data).appendto("#testjson");      number = '<div class="number">' + data.price + '</div>';     $('#myelement').text((number / 100));  }); 

first you're setting number string:

number = '<div class="number">'+ data.price + '</div>'; 

then dividing string 100

in javascript results in nan short not number . specified in spec.

a possible solution divide number 100, , not html string, example:

var number = data.price/100; $('#myelement').text(number); 

this not attach nested div #myelement though.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -