Swift
Swift

Reputation: 54

jQuery selector that finds links whose text doesn't begin with something

I need to add an additional limiter to this find() method so that the <a> elements whose text begin with a string of Re: are left out.

$(document).find(".middletext:not(.quoteheader) > a[href^='http://fakeURL.com/']")

The problem is that I don't know of an attribute to represent the text within an <a> tag, and I don't know of a selector that only selects strings that don't begin with something. If a text attribute existed and if a selector that selects strings that don't begin with something looked like this: ^!=, then my code would be:

$(document).find(".middletext:not(.quoteheader) > a[href^='http://fakeURL.com/'][text^!='Re: ']")

How can I make this work?

I suspect there is a way to use filter() after using find() and make it work, but I don't know how.

Upvotes: 0

Views: 47

Answers (1)

David Thomas
David Thomas

Reputation: 253308

I'd suggest, as you say, using filter():

$(document).find(".middletext:not(.quoteheader) > a[href^='http://fakeURL.com/']")
    .filter(function(){
        return $(this).text().indexOf('Re:') !== 0;
    }).css('color','red'); // or whatever

References:

Upvotes: 1

Related Questions