Test for empty jQuery selection result

前端 未结 3 1957
余生分开走
余生分开走 2021-01-31 13:08

Say I do

var s = $(\'#something\');

and next I want to test if jQuery found #something, i.e. I want to test if s is empty.

<
3条回答
  •  遥遥无期
    2021-01-31 13:46

    if($("#something").length > 0 ){
         // Element found
    }
    else{
        // No element found
    }
    

提交回复
热议问题