arianhojat Posted March 21, 2007 Share Posted March 21, 2007 I am trying to remove a child element from the document, but keep getting an error: In IE, This error is: 'No Such interface supported' In FF. The error is: 'uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.removeChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: file:///W:/ArianTest/HelpDesk/testRemoveChild.html# :: removeTheChild :: line 18" data: no] Line 0' Here is some basic example code, tried 2 ways to remove the hyperlink element. EDIT: 2d way works, but id like to get 1st method working as i have usually used removeChild and wondering why its not working in this case. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function removeTheChild() { var closeRequestDiv = document.getElementById('closeRequest'); var a = closeRequestDiv.getElementsByTagName('a'); var hyperlink1 = a[0]; alert('html='+ hyperlink1.innerHTML); //just to make sure it pulled a hyperlink node, so should output Close //alert('a.#='+ a.length); var aParent = hyperlink1.parentNode; alert('test1'); aParent.removeChild(a); alert('test2'); //never gets here } function deleteNode(elementId) { var label=document.getElementById(elementId); while( label.hasChildNodes() ) { label.removeChild( label.lastChild ); } } </script> </head> <body> Both dont work:<br/> <a href="#" onclick="removeTheChild()">Remove The Child</a> <br/><br/> <a href="#" onclick="deleteNode('closeRequest')">Remove The Child2</a> <div class="request" id="requestID2793"> <div id="closeRequest"> <a href="#">Close</a> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
arianhojat Posted March 21, 2007 Author Share Posted March 21, 2007 doh, aParent.removeChild(a); should be aParent.removeChild(hyperlink1); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.