0

Not long ago i posted a question about this and the solution was to add body as parent like this;

$("#registerF,body").on("change", "input,  select", function () {});

The #registerF element was dynamically loaded and adding body to it fixed the issue.

However I am facing the same problem now and adding body is not working.

I am working on a text editor that uses BBcode just like this one on StackOverflow. Everything is working when I load that page. But when I load it dynamically it is not working and adding body is not working.

Here is the first fonction as an example:

$("#textEdit").on("focus", function () {
    var text = document.getElementById('textEdit');
    text.onkeyup = text.onkeypress = function () {
        preview = this.value;
        preview = bbToHtml(preview);
        document.getElementById('editorPreview').innerHTML = preview;
    }
});    

I try several thing like:

$("#textEdit, body").on("focus", function () {

$("body > #textEdit").on("focus", function () {

Nothing is working in this case. I wonder why it is not working for this but it work's for my form registerF element.

EDIT

I think that what causes the problem is the this statement.

Most of it is working but this part:

$(document).click('#textEdit,.editBout', function (e) {
    //$("#editToolBar,.editBout").click(function (e) { <-------was
    alert('clicked');   <------------get triggered even if i dont click
    e.preventDefault();
    e.stopPropagation();
    console.log(this); <-----------------------------return #document
    var style = ($(this).attr("data-style"));  <---- So this is not working

So instead of this i passed it the element:

 var style = ($('#textEdit,.editBout').attr("data-style"));  <----Work but not dynamiccaly

So its working but still not working if i load in dynamically. the Click is not getting triggered.

MadeInDreams
  • 1,991
  • 5
  • 33
  • 64

0 Answers0