appendChild adds empty DOM-node in IE 11
I am having this real simple piece of Typescript which gives me some questions in IE 11.
The whole task is, get elements out of a list, filter them and put them back in.
So i query the list via
let items = Array.prototype.slice.call(el.querySelectorAll('.pcfilter__results--tile')) as [HTMLElement];
so i have nice array to filter on.
I filter using lodash.
let result = _.filter(items, function(items)
return items.dataset.vehicletype.indexOf(selectValue) >= 0
);
Lets imagine our list to look like this:
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
<li data-vehicletype="bar">
<p> lorem ipsum</p>
</li>
</ul>
So as we filtered it's now time to fill the list back up again i do this via
this.list = el.querySelector('.pcfilter__results--list');
this.list.innerHTML = '';
for (let i = 0; i < result.length; i++)
this.list.appendChild(result[i]);
So what i would now expect would be something like.
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
</ul>
But unfortunately that's not what IE 11 returns me I'm getting this:
<ul>
<li data-vehicletype="foo"></li>
</ul>
So it looks like to me that appendChild() is somehow working in IE 11 but it's only copying the first level not the whole DOM Element including its childs.
Has somebody seen this before? That would be very helpful, thank you!
javascript internet-explorer-11
add a comment |
I am having this real simple piece of Typescript which gives me some questions in IE 11.
The whole task is, get elements out of a list, filter them and put them back in.
So i query the list via
let items = Array.prototype.slice.call(el.querySelectorAll('.pcfilter__results--tile')) as [HTMLElement];
so i have nice array to filter on.
I filter using lodash.
let result = _.filter(items, function(items)
return items.dataset.vehicletype.indexOf(selectValue) >= 0
);
Lets imagine our list to look like this:
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
<li data-vehicletype="bar">
<p> lorem ipsum</p>
</li>
</ul>
So as we filtered it's now time to fill the list back up again i do this via
this.list = el.querySelector('.pcfilter__results--list');
this.list.innerHTML = '';
for (let i = 0; i < result.length; i++)
this.list.appendChild(result[i]);
So what i would now expect would be something like.
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
</ul>
But unfortunately that's not what IE 11 returns me I'm getting this:
<ul>
<li data-vehicletype="foo"></li>
</ul>
So it looks like to me that appendChild() is somehow working in IE 11 but it's only copying the first level not the whole DOM Element including its childs.
Has somebody seen this before? That would be very helpful, thank you!
javascript internet-explorer-11
You probably need to deep-copy the object. (not just the reference)
– Beshoy Hanna
Nov 15 '18 at 20:22
could you provide a code snippet?
– Jannik Müller
Nov 15 '18 at 20:25
add a comment |
I am having this real simple piece of Typescript which gives me some questions in IE 11.
The whole task is, get elements out of a list, filter them and put them back in.
So i query the list via
let items = Array.prototype.slice.call(el.querySelectorAll('.pcfilter__results--tile')) as [HTMLElement];
so i have nice array to filter on.
I filter using lodash.
let result = _.filter(items, function(items)
return items.dataset.vehicletype.indexOf(selectValue) >= 0
);
Lets imagine our list to look like this:
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
<li data-vehicletype="bar">
<p> lorem ipsum</p>
</li>
</ul>
So as we filtered it's now time to fill the list back up again i do this via
this.list = el.querySelector('.pcfilter__results--list');
this.list.innerHTML = '';
for (let i = 0; i < result.length; i++)
this.list.appendChild(result[i]);
So what i would now expect would be something like.
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
</ul>
But unfortunately that's not what IE 11 returns me I'm getting this:
<ul>
<li data-vehicletype="foo"></li>
</ul>
So it looks like to me that appendChild() is somehow working in IE 11 but it's only copying the first level not the whole DOM Element including its childs.
Has somebody seen this before? That would be very helpful, thank you!
javascript internet-explorer-11
I am having this real simple piece of Typescript which gives me some questions in IE 11.
The whole task is, get elements out of a list, filter them and put them back in.
So i query the list via
let items = Array.prototype.slice.call(el.querySelectorAll('.pcfilter__results--tile')) as [HTMLElement];
so i have nice array to filter on.
I filter using lodash.
let result = _.filter(items, function(items)
return items.dataset.vehicletype.indexOf(selectValue) >= 0
);
Lets imagine our list to look like this:
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
<li data-vehicletype="bar">
<p> lorem ipsum</p>
</li>
</ul>
So as we filtered it's now time to fill the list back up again i do this via
this.list = el.querySelector('.pcfilter__results--list');
this.list.innerHTML = '';
for (let i = 0; i < result.length; i++)
this.list.appendChild(result[i]);
So what i would now expect would be something like.
<ul>
<li data-vehicletype="foo">
<p> lorem ipsum</p>
</li>
</ul>
But unfortunately that's not what IE 11 returns me I'm getting this:
<ul>
<li data-vehicletype="foo"></li>
</ul>
So it looks like to me that appendChild() is somehow working in IE 11 but it's only copying the first level not the whole DOM Element including its childs.
Has somebody seen this before? That would be very helpful, thank you!
javascript internet-explorer-11
javascript internet-explorer-11
asked Nov 15 '18 at 20:19
Jannik MüllerJannik Müller
341118
341118
You probably need to deep-copy the object. (not just the reference)
– Beshoy Hanna
Nov 15 '18 at 20:22
could you provide a code snippet?
– Jannik Müller
Nov 15 '18 at 20:25
add a comment |
You probably need to deep-copy the object. (not just the reference)
– Beshoy Hanna
Nov 15 '18 at 20:22
could you provide a code snippet?
– Jannik Müller
Nov 15 '18 at 20:25
You probably need to deep-copy the object. (not just the reference)
– Beshoy Hanna
Nov 15 '18 at 20:22
You probably need to deep-copy the object. (not just the reference)
– Beshoy Hanna
Nov 15 '18 at 20:22
could you provide a code snippet?
– Jannik Müller
Nov 15 '18 at 20:25
could you provide a code snippet?
– Jannik Müller
Nov 15 '18 at 20:25
add a comment |
1 Answer
1
active
oldest
votes
Deep clone the objects you are copying.
(Taken from this SO answer)
JSON.parse(JSON.stringify(obj))
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327306%2fappendchild-adds-empty-dom-node-in-ie-11%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Deep clone the objects you are copying.
(Taken from this SO answer)
JSON.parse(JSON.stringify(obj))
add a comment |
Deep clone the objects you are copying.
(Taken from this SO answer)
JSON.parse(JSON.stringify(obj))
add a comment |
Deep clone the objects you are copying.
(Taken from this SO answer)
JSON.parse(JSON.stringify(obj))
Deep clone the objects you are copying.
(Taken from this SO answer)
JSON.parse(JSON.stringify(obj))
answered Nov 15 '18 at 20:35
Beshoy HannaBeshoy Hanna
4661520
4661520
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327306%2fappendchild-adds-empty-dom-node-in-ie-11%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You probably need to deep-copy the object. (not just the reference)
– Beshoy Hanna
Nov 15 '18 at 20:22
could you provide a code snippet?
– Jannik Müller
Nov 15 '18 at 20:25