I have a list of buttons that load a different url via ajax .get into a specific part of my page.
I have a function that gets the data attr from the click event and passes it onto another function that does a bit of logic.
The problem I have is the new html loaded via ajax is unseen by the js, it also has filter functions in it. I have read a few articles on here about event binding but I cant quite get the synax right for my example. I am not sure how to tie in the ".each" with this type of answer (below).
Jquery `on` event handler: event delegation and passing custom data
I am looking for the correct way to write the following code so that when the html is loaded via the .get request the js "sees" the html.
var filterThemeBtn = $('.js-discoveries__theme-filter');
var counter = 0;
function getDataValueTheme() {
filterThemeBtn.each(function () {
var $this = $(this);
$this.on( "click", {param1: $(this).attr('data-filter')},theme_url);
});
}
function theme_url(e){
// if click event
if (e) {
selectedTheme = e.data.param1;
selectedThemeUrl = "/discoveries/ajax/type/" + selectedTheme + "/" + counter + "/" + "16";
// other logic ect
$.get(selectedThemeUrl, function(data, status) {
grid.append(data);
})
}