<a href="#" data-bs-toggle="modal" data-bs-target="#editLicenseModal" class="edit-license" data-license-id="2" data-customer-id="11">Edit</a>
i want to append data-license-id="2" data-customer-id="11" attribute and values to <button type="button" class="btn btn-primary" id="closeModal" onclick="editLicense()" data-license-id="" data-customer-id="">Edit License</button> this tag
<button type="button" class="btn btn-primary" id="closeModal" onclick="editLicense()" data-license-id="2" data-customer-id="11">Edit License</button>
3
Answers
This code gets all tags with class="edit-license" containing data-bs-toggle="modal" and data-bs-target="#editLicenseModal" then imports params to button with id="closeModal".
Note: JavaScript must be placed after HTML code.
on*
handler. JS should be in one place onlyElement.dataset["someProperty"] = "value"
to assign data (or alternatively, using Object.assign())Or alternatively, you could use Bootstrap Modal events and callback arguments to get the element caller data like in this example that uses jQuery