Question

I have a web page which visitors can change using a formular in that page (a kind of wiki). The piece of code that gives me problems is listed below. This code was working fine but when I added the line of code which appears commented (a jquery replaceWith call) the browser executes the instruction correctly but then the page becomes irresponsive to any event that causes javascript/jquery code to execute. Any ideas what's wrong?

$(document).ready(function(){
  $("#envia").click(function(){
    objectiu = parent.frames[2].document.getElementById(parent.frames[2].id);
    substitut = '<H1>' + document.getElementById("txt1").value + '</H1>';
//  $(objectiu).replaceWith(substitut);
    $.post("xines.py",
    {
      tag: parent.frames[2].tag,            
      par: parent.frames[2].id,
      text: document.getElementById("txt1").value,      // TEXT
      codi: document.getElementById("txt2").value,      // COL·LABORADOR
      idioma: parent.frames[0].document.getElementById("txt3").value,   // IDIOMA
    },
    function(data,status){
      parent.frames[3].document.getElementById("myp").innerHTML= data;         
      parent.frames[2].document.getElementById(parent.frames[2].id).style.color='#000000';
      parent.frames[2].document.getElementById(parent.frames[2].id).innerHTML = document.getElementById("txt1").value;
      document.getElementById("txt1").value = "";
      document.getElementById("txt1").style.backgroundColor = '#FFFFFF';
    });
  });
});

Each element of the web page has a unique id so it is not possible that id refers to multiple elements in the web page, id is assigned in the frame 2 like follows:

$("p").click(function(){            // FUNCTION FOR CLICK ON <P>
    id = this.id;
    this.style.color = '#0000FF';
    parent.frames[1].document.getElementById("txt1").value = this.innerHTML;
    tag = this.nodeName;
    click_doc();
 });
$("h1").click(function(){           // FUNCTION FOR CLICK ON <H1>
    document.getElementById(id).style.color='#000000';
    this.style.color = '#0000FF';
    parent.frames[1].document.getElementById("txt1").value = this.innerHTML;
    tag = this.nodeName;
    id = this.id;
    click_doc();
 });
Was it helpful?

Solution

           objectiu = parent.frames[2].document.getElementById(parent.frames[2].id);
           substitut = '<' + noutag + ' id="' + bakid + '">' + text + '</' + noutag + '>';
           if (noutag!=parent.frames[2].tag) {
              $(objectiu).replaceWith(substitut);
           }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top