Write a jquery selector to select a class with a specific pattern

How to select some divs with a-<random>-c class name template.

+8
javascript jquery html
source share
2 answers

You can find useful information here .

for your case it may work

 $("div:regex(class, .a*c)").jqFunction() 

to match the start of the selector line

 <script>$('input[name^="txt"]').val('content here!');</script> 

this Finds all inputs with an attribute name that begins with 'txt' and places the text in them.

 <script> $("div:contains('new')").css("text-decoration", "underline"); </script> 

Finds all divs containing the "new" and underlines them.

 <script>$('[name$="address"]').val('a letter');</script> 

Finds all the inputs with the attribute name, which ends with the "address" and puts the text in them.

A combination of these features may be useful to you if it helps.

+7
source share

Just use a standard selector that suits the needs of your template, for example. Starts With, Contains, Ends With, or you can use the Regex selector plugin from James Padolsey for regular expression matching.

+1
source share

All Articles