I have a javascript / jQuery page where I use Twitter Bootstrap typeahead. There are two separate places in javascript where I add elements that I would like to be typeaheads. Without asking subjective answers, what is a good way for me to dynamically register input as typeaheads? Give them all the different identifiers and sign up every time I add them? Is there any magic that can be done with .on()?
.on()
You can use delegation jQueryfor this. For instance:
jQuery
$("#element-that-will-contain-typeaheads").on("DOMNodeInserted", function () { $(this).find(".typeahead").typeahead(); });
, typeahead, datepicker etc
typeahead, datepicker etc
, , bootstrap typeahead
bootstrap typeahead
, - :
//add this in your add button click handler $tinput = $('<input type="text" name="bootstrap" class="typeahead"/>'); //apply bootstrap typeahead $tinput.typeahead();
, , :)