JavaScript jQuery .on() “append” jquery append html,jquery append after,jquery append before,jquery

Maybe there's a better way, but I usually add a class like "to_replace" to newly created elements, and then use:

$(".to_replace").each(function() {
    $(this).removeClass("to_replace").choosen();   
})

each time I changed anything.

Answer:1

document doesn't fire a change event. (Edit OP is delegating change)

If you cannot manually bind .chosen() after you append, then you may want to look into MutationObserver, though the browser support is fairly bleeding edge.

Answer:2

You can use livequery plugin https://github.com/brandonaaron/livequery, the best solution would be absolutely https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Events/Mutation_events ,but browser support is really poor.

Answer:3

I just found the answer I needed on another question, but it was never accepted. The answer is by Mario Bellart, Fire OnAppend event for jQuery element when it gets appended to the DOM

How I adapted his code

//Create the dropdown box for the items
var Items = document.createElement("select");
$(Items).attr( {"id":"Items"} );

$(document).on("append", Items,
    function(){
        $(Items).chosen({disable_search_threshold: 100});
        $("#Items_chosen").css({"width":"100px","position":"absolute","left":"5px","top":"20px"});
    }
);

$(document).on("change",Items,
    function(){
        updateHolder(true);
        $(InfoBox).trigger("chosen:updated");
        setTimeout(
            function(){
                $(Items).data('chosen').input_blur();
            }, 100
        );
    }
);

//Add items from ED.listOfItems to HTML Items dropdown box
for(var it in ED.listOfItems){
    var iKey = ED.listOfItems[it];
    var itemOption = document.createElement("option");
    if(!Array.isArray(iKey)){
        $(itemOption).val(iKey);
        $(itemOption).html(iKey.split("_")[0]);
    }
    else{
        $(itemOption).val(iKey[0]);
        $(itemOption).html(iKey[1]);

    }
    $(Items).append( itemOption );
}

/*******Set default to spawn*******/
/**/ ED.objectType = "Spawn";   /**/
/**/ ED.infoType = "";          /**/
/**/ $(Items).val("Spawn");     /**/
/**********************************/

$(MenuBar).append(Items).trigger("append");

I did not know about .trigger() and creating custom events. Maybe I should do some more reading up.

Answer:4

On our website, we have a page where we have 5 images that are buttons. When you click each button, more detailed information appears using the onclick function. What we would like to do is pull the ...

On our website, we have a page where we have 5 images that are buttons. When you click each button, more detailed information appears using the onclick function. What we would like to do is pull the ...

  1. redirect from anchor
  2. redirect with anchor tag
  3. redirect with anchor link
  4. redirect to action from anchor tag

Our company is trying to link a page from a website that's using this code for the link: <a href="#" onclick="startBusinessIntent('guest','Retail','Craft/Hobby Vendor','Guest','BWPublic','Craft/...

Our company is trying to link a page from a website that's using this code for the link: <a href="#" onclick="startBusinessIntent('guest','Retail','Craft/Hobby Vendor','Guest','BWPublic','Craft/...

  1. unable to find page playstation store
  2. unable to find page with socket
  3. unable to find this page
  4. unable to find facebook page
  5. unable to find this page ps store
  6. unable to find this page psn
  7. xatom unable to find page with socket

I have a form element: <form name="formDate"> <input date-picker name="fundacao" ng-model-date="fTit.fundacao" required> </form> And the directive: app.directive('datePicker',...

I have a form element: <form name="formDate"> <input date-picker name="fundacao" ng-model-date="fTit.fundacao" required> </form> And the directive: app.directive('datePicker',...

  1. form not validating on submit
  2. form not validating on submit flask
  3. form not validating on submit django
  4. form not validating
  5. form not validating javascript
  6. form not validating angularjs
  7. form not validating asp.net mvc

I have the following HTML code: <select id="select_opt" class="form-control"> {{# each manageprofile_data}} <option>{{Usergroup}}</option> {{/each}} </select> ...

I have the following HTML code: <select id="select_opt" class="form-control"> {{# each manageprofile_data}} <option>{{Usergroup}}</option> {{/each}} </select> ...