views:

837

answers:

4

Hi,

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

+2  A: 

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

$("a[href*='reorder=+']")
John Fisher
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?Thanks.
Dan
This shows you how to create a custom filter. You can use it, or just take the principles and use them in a .each(function() { ... }). http://www.west-wind.com/Weblog/posts/519980.aspx
John Fisher
A: 

This should work:

$('a[href="reorder=+"]');
Emil Ivanov
None of these solutions seem to be working:(
Dan
Why don't you add the HTML to your question, so we can see more information, then?
John Fisher
A: 

Try this:

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

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)".

awatts