Javascript appenChild() method is not working in IE

Last post 05-19-2009, 2:42 AM by Kenneth. 3 replies.
Sort Posts: Previous Next
  •  10-23-2008, 4:43 PM 45067

    Javascript appenChild() method is not working in IE


     Hi guys,
     
    I want to insert a new div element into the editor document using the appendChild() method.
     
    Javascript Code:-
    /////////////////////////////////////////////////////////////////////////////////
    var e1 = document.getElementById('<%=Editor1.ClientID%>');
    var getDoc = e1.GetDocument();
    var imgElement = document.createElement("img");
    imgElement.setAttribute("src", "logo.jpeg");
    getDoc.getElementById('ParentDIV').appendChild(imgElement);   //Line giving the error in IE
    /////////////////////////////////////////////////////////////////////////////////
     
    The above code is working fine in the Firefox, but it is throwing the javascript error in IE. The error message says "invalid argument". Please let me know where am i making the mistake?
     
    Thanks

    Karan Singh
    (Web Developer)
  •  10-25-2008, 8:08 AM 45090 in reply to 45067

    Re: Javascript appenChild() method is not working in IE

    This is a JavaScript issue.
     
    You're asking the other doc to append a child node created on your doc.
     
    To fix it:
     
    Change

    var imgElement = document.createElement("img");
     
    to:
     
    var imgElement = getDoc.createElement("img");

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  10-31-2008, 1:35 AM 45234 in reply to 45090

    Re: Javascript appenChild() method is not working in IE

    Thanks for the solution. I appreciate you took time to respond.

    Karan Singh
    (Web Developer)
  •  05-19-2009, 2:42 AM 52305 in reply to 45067

    Re: Javascript appenChild() method is not working in IE

    ...
View as RSS news feed in XML