how to set data-target dynamically in jquery code example Example: how to add data modal target attribute in jquery $('#testButton').attr('data-target','#testModal2');