Reputation: 43667
<div>345000000, 46400000000</div>
How do I make two values from the text of this <div>
? They are divided by comma.
We should get var value_1 = 345000000
and var value_2 = 46400000000
Upvotes: 2
Views: 139
Reputation: 19552
Answer: http://jsfiddle.net/morrison/F38FC/
Notes:
String.split()
.Upvotes: 1
Reputation: 18354
<div id="numbers">345000000, 46400000000</div>
<script>
$(document).ready(function(){
var parts = $("#numbers").html().split(",");
var value1 = parseInt(parts[0], 10);
var value2 = parseInt(parts[1], 10);
alert(value1);
alert(value2);
});
</script>
Hope this helps. Cheers
Upvotes: 3
Reputation: 8943
Grab the value, split 'em up.
<div id="nums">12, 15</div>
var str=document.getElementById("nums").innerHTML;
var nums = str.split(",");
alert(nums[0]); //gets first number
Upvotes: 2