Question

I'm replacing a DOM node with HTML returned from an AJAX call. The returned HTML has an id and the DOM node with that id is to be replaced.

The callback function

function updateTrip(xml, success, jqXHR) {
  var para = $(xml);  
  var id = para.attr('id');
  $("#"+id).replaceWith(para);  
}

fails to replace the node although the same code with a fixed id works, and the equivalent raw JavaScript function also works

function updateTrip(xml, success, jqXHR) {
  var para = $(xml).get(0);  
  var id = para.getAttribute('id');
  var div = document.getElementById(id);
  div.parentNode.replaceChild(para, div);   

}

The ids look like n-1.12.2.2.4 ; the content-type is text/html; no errors reported in the FF error console.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top