Search code examples
jqueryhrefattrrel

jQuery element with href AND rel value


If we know that we can use

var link = $('a[href="http://google.com"]');

when we want to find a link with specified href attribute, and also

var link = $('a[rel="myrel"]');

when we want to find a link with specified rel attribute, how can we combine those two attributes so that is possible to find a link with a specified href AND rel in same time?

I have tried with

var link = $("a[rel='myrel', href='http://google.com']");

and

var link = $("a[rel='myrel'][href='http://google.com']");

and it didn't worked


Solution

  • var link = $('a[rel="myrel"][href="http://google.com"]');
    

    This should work fine.

    Here is a demo: http://jsfiddle.net/ScxTV/