I’m working on a text editor. When the user double-clicks on a specific <div>, the contentEditable property is set to true and some editor tools appear. Then, the user can choose between clicking on “save” and “escape”. If he escapes, I want to restore the previous data in this <div>. So I copy data on first double-click (temp['htmlTxt']) and then:
$('#esc').click(function() {
var confEsc = confirm('---\n\nSouhaitez-vous quitter sans enregistrer vos modifications ?\n\n---');
if(confEsc) {
//Do you know why that works :
var id = document.getElementById(temp['myId']);
id.innerHTML = temp['htmlTxt'];
//and why that doesn't work ?
$('#'+temp['myId']).html(temp['htmlTxt'])
}
});
I don’t understand why it works fine with classic JavaScript and not with jQuery…
Those 2 are practically identical. However jQuery does some pre-processing that might be getting in your way…
jQuery Globals
.html(value) setter
that’s straight out of the current version for the setter on
.html(string)so basically if you
value(1) isn’t a string, (2) has a script tag, (3) your on a browser that doesn’t support leading white-space and you string isn’t trimmed, (4) you tag falls into thewrapMapspecial use cases OR (5) innerHTML fails for ANY other reason.. THEN you are essentially calling.empty().append(value)which is a whole different ball of wax… -ck