开发者

How should i get some value from javascript object and check for null

I am getting the element as

   var minPricePerInputField = $("input#A"+indexNr);

The element can be prese开发者_StackOverflow中文版nt also or not also. I am getting some [object Object] thing. I have no idea what is this. I am receiving this [object Object] when the element is not there.


Use

if(   $(minPricePerInputField).length === 0);

means null. no element for that selector.


You are recieveng jQuery object. When there's no such an element, the length property of the recieved object will be 0.


[object Object] is the default toString() of an Object.

When the Object is used in a String context, the toString() is called implicitly.

Whether jQuery matched 0 or more elements won't affect the toString().

jsFiddle.

You can check the length property to check if the selector matched any elements.

jsFiddle.


to get the value of an object.. use object.property

Best way: using jQuery ...see the data by console.log(minPricePerInputField)


var minPricePerInputField = $("input#A"+indexNr);

if(minPricePerInputField.size()==1)
{
   //element exists do something
}


if($("input#A"+indexNr).length == 1){
      alert("Im present");
    }


you can check count of selected element count.

var minPricePerInputField = $("input#A"+indexNr);
if(minPricePerInputField.length == 0){
   return;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜