JQuery: selector containing some text but not containing others

Sorry if this question is dazzlingly easy to answer, but I'm a little new to jQuery and I have a limited time.

I am looking for a selector for text field elements that have this format:

id = "FixedName_#"

"FixedName" will always be "FixedName", but I only want to find elements where # is positive. Therefore, I would like to find "FixedName_1" and "FixedName_2", but skip "FixedName_-1" and "FixedName_-2".

Thank!

The update ended up with something like this (changed my actual code to display here, so I'm not sure if this works, as shown):

$("input[id*='FixedName_']").each(function() {
    if ($(this).attr("id").charAt(10) == "-") {
        //Do something.
    } else{
        //Do something else.
    }
});
+3
6

, . , FixedName_ :

$("[id|=FixedName_#]")

#.

: :

$("[id^=FixedName_#]").each(function(){

var controlNum = parseInt(this.id.replace('FixedName_#',''));
  if (controlNum >= 0){
    //......
  }
});
+2
+1

:

$("*:regex(id, ^FixedName_\\d+$)")

FixedName_0.

+1

,

var elems = $('input:not([id*=-])');

alert(elems.size());
+1

"FixedName", rel , : if ($ ('. FixedName'). attr ('rel') > 0) {... }

0

Is it likely that code that generates text fields can set class attributes such as class = positive / negative based on id? To be able to select $ ('. Positive') ...

0
source

Source: https://habr.com/ru/post/1741135/


All Articles