9

How can I select some divs with class name pattern a-<random>-c.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164

2 Answers2

9

You may find useful information Here.

for your case this might work

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

for matching the starting of selector string

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

this Finds all inputs with an attribute name that starts with 'txt' and puts text in them.

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

Finds all divs containing "new" and underlines them.

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

Finds all inputs with an attribute name that ends with 'address' and puts text in them.

Combination of these may be helpful to you see if it helps

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Devjosh
  • 6,450
  • 4
  • 39
  • 61
  • 2
    You may also find this SO post useful http://stackoverflow.com/questions/190253/jquery-selector-regular-expressions – Devjosh Jul 19 '11 at 05:41
  • 1
    old question and answer, but just want to add that of course `$(div[class^="text"])` would also work. – JHBonarius Apr 22 '22 at 09:07
1

Just use the standard selector that meets the needs of your pattern e.g. Starts With, Contains, Ends With, or you can use the Regex selector plugin from James Padolsey to match based on a regular expression.

Clayton
  • 5,330
  • 1
  • 18
  • 15