2

I have this code:

openPopup.hide();

var substr = popupId.split('-');                        
var clone = $("#popup"+substr[1]).clone(true);

$("#popup"+substr[1]).remove();
$(openPopup).html(clone);
$.dimScreenStop();

It works well in IE 7, IE 9, Chrome, Firefox.

I have tracked the problem down to the line "var clone = $("#popup"+substr[1]).clone(true);". This by adding "alert("Test");" between all the lines and after that line (in IE8) it doesn't output the alert.

The strange thing is that I get error in the jquery min-file (just in IE8 no other browser, or browser version):

SCRIPT5007: Unable to get value of the property 'nodeType': object is null or undefined jquery.min.js?ver=3.4.1, line 2 character 4426

JohnSmith
  • 417
  • 4
  • 10
  • 21

2 Answers2

5

You can call the javascript DOM API cloneNode() method instead of jQuery's clone(). More informations on MDN

Example :

var clone = $("#node").get(0).cloneNode(true);
var $clone = $(clone); // JQUERY object

$('#copy').empty().html($clone.html());​

===> Demo

MyBoon
  • 1,290
  • 1
  • 10
  • 18
  • Thanks for answer! The thing is that this "script" is a popup wiith a youtube video in it, which displays when you click a link. I want be able to click the link, get the popup and then close it multiple times. So if Im right, the code above wont work the second time clicking the link? – JohnSmith Oct 02 '12 at 08:16
  • I don't understand what you want to do, but cloneNode is an alternative for clone in IE. – MyBoon Oct 02 '12 at 11:53
2

.clone() gives you a jQuery extended element and not HTML text. Even though .html() is accommodating enough to accept jQuery objects, this is not what it was originally intended for.

As a solution, try using $(openPopup).empty().append(clone); instead of $(openPopup).html(clone);

techfoobar
  • 65,616
  • 14
  • 114
  • 135
  • Thanks for answer! Im afraid that it doesn't help. The problem is on the line "var clone = $("#popup"+substr[1]).clone(true);" in IE8, because It doesn't execute anything below that line. So editing the line .html(clone); want affect. – JohnSmith Oct 02 '12 at 07:55
  • Oh.. Ok. Try alerting the value of `substr[1]` before cloning. `alert(substr[1])` - That might give you some hints. – techfoobar Oct 02 '12 at 07:57
  • It works fine, alerting the id in the end of the div-id name. – JohnSmith Oct 02 '12 at 08:40