How to access a group of elements in jQuery within a single function?
For example to the link:

a[href^="page-1.html#"] 

This syntax does not work for me:

 $('a[href^="page-1.html#"]', 'a[href^="page-2.html#"]').click(function(e) { e.preventDefault(); }); 

    1 answer 1

    You have a comma between the quotes, and you need inside.

     $('a[href^="page-1.html#"], a[href^="page-2.html#"]').click(function() { alert('Нажал'); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="page-1.html#">Ссылка 1</a> <a href="page-2.html#">Ссылка 2</a>