-1

Is it possible to somehow intercept element.innerHTML = msg; in one particular location and run it:

$("#id").text(msg);

instead of .innerHTML = msg?

http://jsfiddle.net/j8b4zoLt/

UPDATE:
I've found the similar question: how to intercept innerHTML changes in javascript?
and as I understand the interception innerHTML is not possible.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
DmitMedv
  • 980
  • 3
  • 11
  • 22
  • I have no idea what you're asking, but the answer is yes, it's probably possible, and the answer is no, you probably don't want to do it. If you want to stop `innerHTML` if the element contains other nodes, and not just text, that sure is possible, the question is why. – adeneo Jan 29 '15 at 13:27
  • How about just not using `innerHTML` in the first place unless you really need it? It looks like you're already using jQuery anyway, so just use `.text()`. – JLRishe Jan 29 '15 at 13:32
  • Didn't realy understand the question, but could that be what you want? `element.html('
    '+msg+'
    ');`
    – gr3g Jan 29 '15 at 13:34
  • See: http://jsfiddle.net/0motnqaa/ It is a fix of your jsfiddle code, but I don't understand how it connected with your question. – Tarwirdur Turon Jan 29 '15 at 13:34
  • `var element = $('#msgBox').children('.msgContent');` – gr3g Jan 29 '15 at 13:36
  • @OP, could you please describe to us the _actual_ issue you are facing rather than the solution that you think you want? If you do that, we might be able to propose a solution. [What is the XY problem?](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – JLRishe Jan 29 '15 at 15:44

1 Answers1

-1

This code should work

insertIntoMsgBox = function(msg) {
  //...
  var element = $('.msgContent') ; 
  element.html(msg) ;
  //...
}
ziz194
  • 312
  • 2
  • 8
  • 22