Uncaught error NOT_FOUND_ERR DOM Exception 8

So, I delete all the content under a specific div and add the contents of the message. However, javascript throws the following error after finishing:

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 

Here is the code in which 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 noted that the problem is with how I assigned divMessage to reviewSheet . I tried both adopt and appendChild , but no one works. A little help would be appreciated.

+6
source share
2 answers
 divMessage.style.color="rgb:(105,105,105)"; 

it should be

 divMessage.style.color="rgb(105,105,105)"; 
+3
source

Is the problem you are calling the hasChildNodes () method for a jQuery object? I'm not sure what $ ("reviewSheet") should be, but wrapping a line in $ () makes a jQuery object, which I suppose won't work with regular javascript methods. If "reviewSheet" is the item id, you can do something like

 node = document.getElementById('reviewSheet'); 

then you can enter the while loop.

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

You also need to put a bracket after hasChildNodes () to return a boolean.

+1
source

Source: https://habr.com/ru/post/898255/


All Articles