I have the following jquery/Javascript code which creates a new button on the screen
$("#prefixed-list").append(`
<li class="list-group-item d-flex my-auto mx-auto border-0" order="9999999999">
<button type="button" class="btn btn-info mt-3" onClick="prefixCall(urlDomain, searchContent, offset)">Load More</button>
</li>
`);
urlDomain, searchContent, offset are all variables defined in the same function. Currently when the button gets created on the page
<button type="button" class="btn btn-info mt-3" onclick="prefixCall(urlDomain, searchContent, offset)">Load More</button>
I want it to have the value of the variables. How can that be done?
2
Answers
You can add event handler
on(eventname,[eventData], callback)
. This allow to listen the events from the elements you append dynamically.You can like this:
Best regards,
Bogdan Bob.
since you’re already using template literal,
${urlDomain}
etc