Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery attribute selector: anything but not ending with specified string?

I need to select elements in jquery, attibute values of which do not end with a specified substring.

It must be an equivalent to "match all elements but those that end with a given substring in that attribute".

So that e[a!@#=finstr] matches e, e a="finstring" etc, and does NOT match e a="somethingfinstr", e a="finstr".

Help, thanks.

like image 365
Dennis Berg Avatar asked Nov 29 '11 07:11

Dennis Berg


People also ask

Which is the correct jQuery selector to select?

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.

Which selects elements that have the specified attribute with a value beginning exactly with a given string?

attributeStartsWith selector Description: Selects elements that have the specified attribute with a value beginning exactly with a given string.

When working with attribute selectors how can you select elements which contain a particular attribute value?

The [attribute|="value"] selector is used to select elements with the specified attribute, whose value can be exactly the specified value, or the specified value followed by a hyphen (-). Note: The value has to be a whole word, either alone, like class="top", or followed by a hyphen( - ), like class="top-text".


3 Answers

Something along the lines of

$(':not([name$="finstr"])')

Should do the trick!

Edit: alternatively

$(selector).not('[name$="value"]');
like image 134
Willem Mulder Avatar answered Oct 03 '22 11:10

Willem Mulder


I think this would work, using links as an example -

$("a:not([id$='hello'])"

Demo - http://jsfiddle.net/CJH2M/

like image 33
ipr101 Avatar answered Oct 03 '22 11:10

ipr101


Try inverting the: Attribute Ends With Selector [name$="value"]. with jQuery(':not(selector)').

Something like this: :not([name$="value"])

like image 30
Drejc Avatar answered Oct 03 '22 09:10

Drejc