WRONG_DOCUMENT_ERR: DOM Exception 4 in Safari/Chrome

I'm getting the following error in my jQuery/Javascript code when I run it on Webkit-based browsers: WRONG_DOCUMENT_ERR: DOM Exception 4. When I get the error, what I'm doing is loading an external XML document (that's XHTML compliant) and replacing one of the nodes in my original web page with a node from the XML document. This works fine in Firefox and Opera. Does anybody know how I get this to work? I posted the code below. Thanks.
$('.link').click( function() {
	// this.href must point to a well-formed XHTML file or the stylesheets won't work
	$.get(this.href, function(data, textStatus) {
		try {
			$('#main').replaceWith($('#main', data));
                        // there's a <div> node in the original web page with id="main" and a <div> node in the XML page with id="main"
		}
		catch(e) {
			alert(e);           // this gets triggered
		}
 
                // do more stuff
        }
}

Open in new window

tjgquickenAsked:
Who is Participating?
 
Albert Van HalenConnect With a Mentor Analyst developerCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.