Why does chrome throw "Uncaught Error: NOT_FOUND_ERR: DOM Exception 8" here?
Asked Answered
E

3

20

Below is the code for my YWA wrapper

var astr_ywascript = (document.createElement("script").type = "text/javascript").src = "http://d.yimg.com/mi/eu/ywa.js";
document.head.appendChild(astr_ywascript); // <- error on this line

It's run on page load, so it makes no sense that JS can't find the document head tag.

Any ideas?

Thanks


Opera throws this error on the same line. Uncaught exception: Error: WRONG_ARGUMENTS_ER Firebug says: document.head is undefined [Break On This Error] document.head.appendChild(astr_ywascript);

Ernie answered 7/1, 2011 at 9:19 Comment(0)
V
16

In the line

(document.createElement("script").type = "text/javascript").src

you are setting the src property of a string. The assignment in parentheses returns the assigned value. You make the same mistake later in the line, ultimately assigning "http://d.yimg.com/mi/eu/ywa.js" to astr_ywascript

Split it out onto separate lines:

var el=document.createElement("script");
el.type="text/javascript"
el.src=...
document.head.appendChild(el);

Raw Javascript rarely behaves in the fluid way one gets used to with jQuery.

You might also want to get the head as follows:

document.getElementsByTagName("head")[0]
Vltava answered 7/1, 2011 at 9:25 Comment(0)
V
8

I got this error with Backbone.js because I was doing:

$('#backbone').html(@view.render())

Instead of

$('#backbone').html(@view.render().el)

Like I should have done. Still don't really know what this 'el' business is, but I'm sure I'll figure it out soon.

Venetis answered 23/9, 2011 at 22:1 Comment(3)
.el is Backbone's reference to the element that gets updated by render(). You probably have return this; in your render() method, which returns a reference to the Backbone View itself, when it sounds like you were expecting return this.el which would let you do $(...).html(@view.render())Obeah
This comment just solved a MASSIVE headache for me! I'd be interested to know why the convention is to do 'return this' from the render function rather than returning this.el?Yearling
I was getting the same problem when passing an array to .append() function. Instead of passing simple html text I passed an array of html text and that made the issue happen.Anthropomorphosis
H
0

Just appending this answer for people who might hit this page like I did while searching for an answer to a “Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 error.

I had this error in Chrome. In my case I was using .appendChild(ttt);

The issue was that ttt was an array object instead of the div I intended to append.

So make sure what you are appending is actually a DOM object and not accidentally a different object type.

Handbill answered 1/8, 2013 at 8:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.