If you are trying to access an element with data-* attributes, as it would be in Bootstrap , we can select such elements as follows: -
var loginBtn = $('a[data-target="#login-modal"]');
This is the same as the accepted answer, except that it has a "" around #login-modal . Without a "" it does not work.
Good luck.
source share