Struggling to figure out why the solutions I find are not working for me. It seems like it may be related to my understanding of how elements load in a specific order.
I have a common issue - trying to pass data from a button into a modal it triggers. Specifically, I want to pass an id. The typical solution often found on Stack Overflow involves using code like this:
HTML:
<button class="btn btn-primary btn-block" data-toggle="modal" data-target="#myModal" id="product-button">Product Name</button>
JavaScript:
$(function() {
$('#product-button').click(function() {
var productId = $(this).attr('name');
$(".modal-body #testContainer").val(productId);
});
});
You can see an example here: Passing data to a bootstrap modal
However, this doesn't seem to work for me. My situation is unique because the buttons are generated dynamically. I suspect that my helper function might be getting tied to the page before these dynamic buttons are created, causing it to miss the .click event (the buttons appear after a search query).
If anyone has any suggestions on how I can overcome this challenge and successfully pass data to a modal in this scenario, I'd greatly appreciate it!