Skip to content Skip to sidebar Skip to footer

How To Send Parameter Based On Which Button Is Clicked In Modal?

Demo and full code is like this : https://jsfiddle.net/oscar11/o5qn5gum/5/ My HTML code is like this :
&

Solution 1:

this inside the show.bs.modal event, refers to the modal itself, while the json data attribute is set at the button. You can access the button that triggered the event at e.relatedTarget.

var json = $(e.relatedTarget).attr('data-json');

Furthermore, accessing a data- attribute with $.data will automatically parse JSON. So you could instead write:

var json = $(e.relatedTarget).data('json');

... and skip JSON.parse, as json is now an object and not a string.


Post a Comment for "How To Send Parameter Based On Which Button Is Clicked In Modal?"