uncaught error NOT_FOUND_ERR DOM Exception 8
Asked Answered
T

2

6

So I am deleting all the contents under a particular div and adding a message content. However, javascript throw the following error after the finish:

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8

Here is the code where it is executed

 new Ajax.Request("profileThis.php",
 {
   method:'post',

   parameters:{title:title, review:review, userId:userId, category:category, categoryId:categoryId},

   onSuccess:function(ajax) 
   {
    alert(ajax.responseText); // this is just for debugging purposes

    var message=ajax.responseText;

    var divMessage=document.createElement("div");

    divMessage.style.color="rgb:(105,105,105)";

    divMessage.innerHTML=message;

    while($("reviewSheet").hasChildNodes)
    {
     $("reviewSheet").removeChild($("reviewSheet").lastChild);
    }

    $("reviewSheet").adopt(divMessage);         

   },

   onFailure:ajaxFailure,

   onException:ajaxFailure

 });

People commented that the problem was with how I assigned divMessage to reviewSheet. I tried both adopt and appendChild but none works. A little help would be appreciated.

Turkic answered 29/9, 2011 at 4:49 Comment(2)
$("reviewSheet") What it's? You uses javascript frameworks, or it an alias for document.getElementById()? If you need to remove all nodes from element (empty element) simply use element.innerHTML='';Davit
Or instead of element.innerHTML='' use code: while(someParentElement.firstChild)someParentElement.removeChild(someParentElement.firstChild);Davit
P
3
divMessage.style.color="rgb:(105,105,105)";

should be

divMessage.style.color="rgb(105,105,105)";
Parrakeet answered 29/9, 2011 at 4:52 Comment(1)
Thanks but that did not work. I tried but its still displaying the same. I don't think its a CSS issue.Turkic
B
1

Is the problem that you are calling the method hasChildNodes() on a jQuery object? I'm not sure what $("reviewSheet") is supposed to be, but wrapping a string in $() makes it a jQuery object which I don't believe will work with regular javascript methods. If "reviewSheet" is the id of an element you could do something like

node = document.getElementById('reviewSheet');

then you could go into your while loop.

while (node.hasChildNodes()) {
 //the rest of your code here
}

Oh also you need to put the parenthesis after hasChildNodes() to return a boolean value.

Bdellium answered 11/3, 2012 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.