Search code examples
jqueryclickhref

Target specific href with jQuery


I'm using this code to open multiple links on a page, http://fiddle.jshell.net/njA8z/1/

But -- 1. I want the code to target only hrefs within a div with class links ---
2. I'll need to re-use same code on another page but to target all links with class links ex.

<a href="#!mylink" class="links">Link</a>

Appreciate any help.


Solution

  • You can try using jQuery's .hasClass() method.

    Something like this should work

    if($('div').hasClass('links')){
        // do what you need to with the links in here
    }