0

I want to check to see if the first node of a div is number and if it's null I'll display a div or not.

http://jsfiddle.net/NsXsa/

            $(".carcount").bind("DOMSubtreeModified",function(){

    $(function() {
        $(".carcount span").filter(function() {
            var carnumber = get(0).firstChild.data; 

            if ($.isNumeric(carnumber)) {
                $('.carcount').css({ 'display': 'none' });
                    }                   

            else {
                $('.carcount').css({ 'display': 'block' });
                }                       
        });
    });
}); 
Talha
  • 350
  • 1
  • 4
  • 19

2 Answers2

0

Use this :

$.isNumeric(carnumber )

It's a built in function in jquery.

https://api.jquery.com/jQuery.isNumeric/

Royi Namir
  • 144,742
  • 138
  • 468
  • 792
  • `$(".carcount").bind("DOMSubtreeModified",function(){ $(function() { if([0].firstChild.data.isNumeric($('.carcount').val())) { $('.carcount').css({ 'display': 'none' }); } else { $('.carcount').css({ 'display': 'inline' }); } }); });` Like this? – Talha Mar 03 '14 at 06:27
0

Check console and see whats the value of carnumber using console.log(carnumber)

You might also have to use parseInt() to convert string to number.

 $(".carcount").bind("DOMSubtreeModified",function(){
    $(function() {
        $(".carcount").filter(function() {
            var carnumber = parseInt(get(0).firstChild.data, 10); 
            if ( carnumber < 2 ) {
                $('.extra-zero').css({ 'display': 'none' });
                    }                   
            else {
                $('.extra-zero').css({ 'display': 'inline' });
                }                       
        });
    });
}); 
SajithNair
  • 3,867
  • 1
  • 17
  • 23