Reputation: 745
Is it possible to observe the the "load"event when elements have been created in the DOM? More specific, I'm interested in observing if new select boxes have been added, and then sort the options in the selectbox.
I've tried stuff like:
$("select").live("load", mySortSelectFunction)
This apparently does not work. Maybe the "load" event doesn't fire on the select element?
If there is no "load" event, then how would it be possible to get a notification when a select box is ready in the DOM? I want to avoid firing some custom event from code everywhere the selectboxes are created. I want to just add one little eventlistener in a global script, and then all selectboxes are automatically sorted no matter when they are created.
Kind regards,
Christian Sonne Jensen
Upvotes: 1
Views: 1049
Reputation: 69915
There is not such event or functionality that you can achieve. You can basically try to find all select elements on page load and then apply the sorting function
$(document).ready(function(){
$("select").each(function(){
mySortSelectFunction(this);
});
});
Upvotes: 0