I am really new to jQuery and facing a problem here. I have a html container element and want dynamically add elements in that container. Every element has a close/remove button in the right corner. On click of that button the element should be removed.
At the moment I trigger a function which adds the button styling and the click event handler to the remove button of the element everytime an element is added to the container.
jQuery( ".closeButton" ).button({
icons: {primary: "ui-icon"},
text: false }).click(function() { Click Event here ... });
This works at the moment, but I thought I found a more comfortable solution with the .on() function I read here: In jQuery, how to attach events to dynamic html elements?
With
$('container').on('click', '.closeButton', function() {
//remove element
});
I can add the click element to that button, but I want to add the jQuery UI Button Styles, too. I mean:
icons: {primary: "ui-icon"},
text: false
Is it possible with .on() method to do so?