Search code examples
javascriptdomqueryselector

How can I find all <a> tags that match a certain pattern?


I want to match all a tags that have example.com/app in the href. How can I do this with JavaScript?


Solution

  • You can use querySelectorAll with a css attribute selector:

    document.querySelectorAll('a[href="www.example.com"]')