-2

I am using jQuery on my website, specifically the children method so I can get to lower levels of my HTML. This works fine on Chrome and Firefox, but when I use it on Internet Explorer, I get the following error:

error: object doesn't support property or method 'children'

Is this an error in IE or am I doing something wrong? Here are the lines where its pulling the error:

parent = $(this).parent().parent().parent();
parent.children().children().children().attr('id');

Is it possible that IE doesn't like it when you write children() that many times?

Any help would be greatly appreciated. I just don't understand why IE would have a problem with this now, since I have used the children() method before.

Whymarrh
  • 13,139
  • 14
  • 57
  • 108
Doctor06
  • 677
  • 1
  • 13
  • 28

1 Answers1

3

The 1st line could be trying to reassign the predefined global, window.parent. While doing so may not throw an error, the global can be read-only and discard the assigned value:

parent = 'parent';
console.log(parent); // null or Window rather than 'parent'

If the snippet is within a function, make sure you declare the variable so it's locally scoped:

function foo() {
    var parent = $(this)....;
    // ...
}

Or, use a different identifier to avoid the conflict.

var $parent = $(this)....;
$parent.children()...;
Community
  • 1
  • 1
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199