Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 303
thecodeparadox Avatar asked Jul 19 '11 05:07

thecodeparadox


2 Answers

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

like image 170
Devjosh Avatar answered Nov 15 '22 21:11

Devjosh


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.

like image 41
Clayton Avatar answered Nov 15 '22 20:11

Clayton