0

While this syntax works on all other browser, safari on windows throws an error

$("#kibana").contents().find('.navbar-nav')[0].remove();

The error is

TypeError: 'undefined' is not a function 

The element does exist. I checked using the debugger.

Why is this happening?

Denzz
  • 1,025
  • 2
  • 11
  • 18
  • "kibana" is id of iframe in which I am downloading third party content. and before executing this $("#kibana").contents().find('.navbar-nav')[0].remove() when I am checking in debugger, $("#kibana").contents().find('.navbar-nav') shows me array with 2
      . So I am trying to remove the first one via this code.
    – Denzz Jun 13 '15 at 00:18
  • Looks like somebody did experience an issue with `iframe` on Safari as well, but not directly relavant. http://stackoverflow.com/questions/14105611/iframe-not-working-in-safari – TaoPR Jun 13 '15 at 00:23

1 Answers1

0

When you use [] on a jQuery object, you are retrieving the underlying DOM node. .remove isn't fully cross-browser compatible on native DOM elements.

Instead, you can use .eq to retrieve the element while still having it wrapped in jQuery. That way you can use the cross-browser comptabile .remove method:

$("#kibana").contents().find('.navbar-nav').eq(0).remove();
Stryner
  • 7,288
  • 3
  • 18
  • 18