Why does .length always return 0 in this code?

conan

I am trying to check if a div exist or not for the purpose that someone might get the result or not.

If the user get the result then class display_box will exist.

So I am using .length to check the class display_box exist or not; however, I have test that it always return 0 no matter there was a class or not.

I try to use ID.

I tried to use $myDiv.html().length

I tried .text(), .content().

I had tried .is(:empty) too. Is that because ajax, so basically, it will consider the class is not existed at all?

ajax_search_load();//this is function to load my ajax 


		var $myDiv = $('.display_box');

		    if ( $myDiv.length==0){
				alert('fsdfa');
		    }
		

Victor

As @Vohuman said, if you are making an asynchronous call, then execute your function in the callback of your ajax request, example:

$.ajax({
    url : 'foo.bar',
    type: 'GET',
    success : function (data) {
        //show your data
        $('#some-container').html(data);

        //find your div
        var $myDiv = $('#some-container').find('.display_box');

        //do some stuff
        if ( $myDiv.length==0){
            alert('fsdfa');
        }
    }
})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does this return a 0 length?

From Dev

Why does this return a 0 length?

From Dev

Python: Why does the value always return 0

From Dev

Why does ListBox AlternationIndex always return 0

From Dev

Why does this function always return 0

From Dev

Why does my code return 1 always?

From Java

Why does "decimal.TryParse()" always return 0 for the input string "-1" in the below code?

From Dev

$(":animated").length - Always return 0

From Dev

Why PyObject_IsInstance always return 0 in my sample code

From Dev

Why PyObject_IsInstance always return 0 in my sample code

From Dev

Why does TotalCount property on public folder always return 0 items?

From Dev

Why does the following mongodb group query return always 0?

From Dev

Why does my recursive factorial method always return 0?

From Dev

Why does "n&1 == 0" always return false?

From Dev

Why does this method always produce 0 as its return value?

From Dev

Why does sudo -n on Mac OS X always return 0?

From Dev

Why does my Excel COUNTIF function always return a value of "0"?

From Dev

Why does this method always produce 0 as its return value?

From Dev

Why does my Perl calculator always return 0?

From Dev

Why does my LINQ query always return 0?

From Dev

Why does conversion to extFloat80_t always return 0?

From Dev

Why does this piece of code always return "no_conflict"?

From Dev

Why does this code return undefined method 'length' for nil::NilClass?

From Dev

Why this code return always undefined?

From Dev

Why does a=0; let a++ return exit code 1?

From Dev

Remote Command executed via ssh does not return proper return code. Return error code is always "0", even condition failed

From Dev

Writing a max cost algorithm that seems to always return 0. Why does it loop through the entire data set and only return '0'?

From Dev

Why WP AJAX always return 0?

From Dev

why selector.select() is always return 0

Related Related

  1. 1

    Why does this return a 0 length?

  2. 2

    Why does this return a 0 length?

  3. 3

    Python: Why does the value always return 0

  4. 4

    Why does ListBox AlternationIndex always return 0

  5. 5

    Why does this function always return 0

  6. 6

    Why does my code return 1 always?

  7. 7

    Why does "decimal.TryParse()" always return 0 for the input string "-1" in the below code?

  8. 8

    $(":animated").length - Always return 0

  9. 9

    Why PyObject_IsInstance always return 0 in my sample code

  10. 10

    Why PyObject_IsInstance always return 0 in my sample code

  11. 11

    Why does TotalCount property on public folder always return 0 items?

  12. 12

    Why does the following mongodb group query return always 0?

  13. 13

    Why does my recursive factorial method always return 0?

  14. 14

    Why does "n&1 == 0" always return false?

  15. 15

    Why does this method always produce 0 as its return value?

  16. 16

    Why does sudo -n on Mac OS X always return 0?

  17. 17

    Why does my Excel COUNTIF function always return a value of "0"?

  18. 18

    Why does this method always produce 0 as its return value?

  19. 19

    Why does my Perl calculator always return 0?

  20. 20

    Why does my LINQ query always return 0?

  21. 21

    Why does conversion to extFloat80_t always return 0?

  22. 22

    Why does this piece of code always return "no_conflict"?

  23. 23

    Why does this code return undefined method 'length' for nil::NilClass?

  24. 24

    Why this code return always undefined?

  25. 25

    Why does a=0; let a++ return exit code 1?

  26. 26

    Remote Command executed via ssh does not return proper return code. Return error code is always "0", even condition failed

  27. 27

    Writing a max cost algorithm that seems to always return 0. Why does it loop through the entire data set and only return '0'?

  28. 28

    Why WP AJAX always return 0?

  29. 29

    why selector.select() is always return 0

HotTag

Archive