thecodeparadox
thecodeparadox

Reputation: 87073

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.

Upvotes: 9

Views: 8469

Answers (2)

Devjosh
Devjosh

Reputation: 6496

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

Upvotes: 9

Clayton
Clayton

Reputation: 5350

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.

Upvotes: 1

Related Questions