Dan
Dan

Reputation: 1011

jQuery, escape characters when selecting by href

I'm trying to select an element based on its href within a table of records. I have two links for each record:

'reorder=+' and 'reorder=-'

If I use

a[href*=reorder]

both elements are recognised successfully, however if I try to differentiate between the two, nothing happens eg:

a[href*=reorder\=\+]

Is there a way around this?

Thanks

Upvotes: 1

Views: 1673

Answers (4)

awatts
awatts

Reputation: 1067

Dan, Given your comment

Apologies, my mistake. The actual href values were reorder=-(id) or just reorder=(id). Is there a way to filter based on the absence of a character?

the selector you need to use is:

$("a[href*='reorder=']:not([href*='reorder=-'])")

This selects all anchors where the href contains "reorder=" and then removes all those which contain "reorder=-", thus leaving those which are of the form "reorder=(id)".

Upvotes: 0

Eric
Eric

Reputation: 97691

Try this:

$('a').filter(function()
{
    return $(this).attr("href").IndexOf("reorder=+")!=-1;
})

Upvotes: 0

Emil Ivanov
Emil Ivanov

Reputation: 37673

This should work:

$('a[href="reorder=+"]');

Upvotes: 0

John Fisher
John Fisher

Reputation: 22727

Have you tried this? The quotes may make a difference.

$("a[href*='reorder=+']")

Upvotes: 2

Related Questions