I am reading the innerHtml of two span’s and each are numeric values, for instance a 6 and 14.
I can store them in var’s and detect them, but what I need to try and do is read them as numeric values to use in the if statement, but its not working.
function countingRecords() {
var recordsShown = $("#RecordsShown").text();
var recordsTotal = $("#TotalNumberOfRecords").text();
alert(recordsShown + recordsTotal);
// this alert shows 614, the 6 is one and 14 the other
if (recordsShown < recordsTotal) {
alert("test");
}
}
The first alert is just for my benefit really, its the if statement I’m stuck with, its not recognising when the one value is less than the other value in a numeric sense.
Tried this too and again its not working
if ($(recordsShown).val() < $(recordsTotal).val()) {
$("#TotalNumberOfRecords").after("<span class='returnRecordsToAll'>clear</span>");
//alert("test");
}
Tried this too and get NaN as the alert
var recordsShown = parseInt('#RecordsShown');
var recordsTotal = parseInt('#TotalNumberOfRecords');
alert(recordsShown + recordsTotal);
Javascript does NOT do implicit type conversion for number string comparitors if it can help it - If passed two number strings as operands of a comparitor, it will do a STRING comparisson between the two - thus, “120” < “20” is TRUE.