1

I have an array on javascript and i insert the elements on it like this:

 var parentRow = $(button).parent().parent();
 list.push({ parent: parentRow, detailRow: newRow });

On the click of another button i do the following:

      var parentRow = $(button).parent().parent();
      var detailRow = null;

      for (var i in list) {
        if ($(list[i].parent) == $(parentRow)) {
          detailRow = list[i].detailRow;
        }
      }

The point is: The if comparing to two elements should return TRUE, because they are the same DOM element....the same i added before, but it return FALSE.

I would like to know how i compare this two elements to get TRUE there.

Alan Araya
  • 701
  • 1
  • 12
  • 27

3 Answers3

1

Try:

if (parentRow.has(list[i])) {
David Downes
  • 1,145
  • 10
  • 24
1

They are not the same objects, because they don't refer to the same jQuery instance.

Simple solution: Don't use jQuery and do it with normal DOM methods.

jQuery solution: Use .is()

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

You need to compare the native elements, not the jQuery-wrapped elements. jQuery's DOM methods returns not the elements themselves but a jQuery object.

if (list[i].parent[0] === parentRow[0]) {