0

I am getting the element as

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

The element can be present 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.

Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
  • If you use firebug (or another similar) you could breakpoint the code in the browser and take a look at the object, this would help you no end. – RubbleFord Jul 21 '11 at 06:58

7 Answers7

1

Use

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

means null. no element for that selector.

Vivek Goel
  • 22,942
  • 29
  • 114
  • 186
  • @Saurabh Kumar nops It will be "===". Read http://stackoverflow.com/questions/3735939/jslint-expected-and-instead-saw for more details. – Vivek Goel Jul 21 '11 at 07:05
1

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

Igor Dymov
  • 16,230
  • 5
  • 50
  • 56
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.

alex
  • 479,566
  • 201
  • 878
  • 984
0

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

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

xkeshav
  • 53,360
  • 44
  • 177
  • 245
  • This will log `[Object object]`. Even if no matching elements are found, a transient jQuery object will still be created and returned... – Björn Jul 21 '11 at 07:04
0
var minPricePerInputField = $("input#A"+indexNr);

if(minPricePerInputField.size()==1)
{
   //element exists do something
}
Praveen Prasad
  • 31,561
  • 18
  • 73
  • 106
0
if($("input#A"+indexNr).length == 1){
      alert("Im present");
    }
vhtellez
  • 156
  • 1
  • 8
0

you can check count of selected element count.

var minPricePerInputField = $("input#A"+indexNr);
if(minPricePerInputField.length == 0){
   return;
}
Ethem Kuloglu
  • 703
  • 1
  • 5
  • 9