There are two buttons that invoke modal windows.

<a class="btn-show-modal js-show-modal" href="#js-block-modal">modal window</a> <a class="btn-show-modal js-show-modal" href="#js-block-modal2">modal window 2</a> 

Then there is the jQuery script which calls these windows when you click on the button with the .js-show-modal class. The script receives the #js-block-modal attribute and calls up the window. The question why the script always gets the attribute of the first button when I click on the second

  $('.js-show-modal').on('click', function(e){ e.preventDefault(); var currentModal = $('.js-show-modal').attr('href'); $(currentModal + ', #js-overlay').fadeIn('fast'); }); 

    1 answer 1

    You do not take the current element that clicked, but the first element. Correctly working code:

      $('.js-show-modal').on('click', function(e){ e.preventDefault(); var currentModal = this.attr('href'); $(currentModal + ', #js-overlay').fadeIn('fast'); }); 

    Thus, you will get the current item through this .