how to add data modal target attribute in jquery

JavaScript
$('#testButton').attr('data-target','#testModal2');

Source

Also in JavaScript: