jquery how to select all the class elements start with "text-"?

Try this. For more details refer jquery selectors

$('*[class^="text"]')

You don't necessarily need to specify asterisk *, you can do this too:

$('[class^="text-"]')

Notice the addition of - after text something you are looking for.

Check out the jQuery starts with selector for more information.


Here's an attempt at a solution that's both accurate and not too slow:

var elts = $('*[class*="text-"]')
  .filter(function () {
    return this.className.match(/(?:^|\s)text-/);
  });

Which works by using the (hopefully) fast Sizzle code to find elements that have "text-" anywhere in their class attribute, and then calls a function on each of those to filter them down to the ones that actually have "text-" at the beginning of a class name.