Home > Mobile >  How to grab all instances of a partial class name
How to grab all instances of a partial class name

Time:12-08

I'm trying to reinitialize a variable that gets all instances of a class name. Here's my code for reinit:

newContent = $(".product-sample-field[class^='appended']");

And for reference, my HTML looks like this:

<tr class="product-sample-field appended1">...</tr>
<tr class="product-sample-field appended2">...</tr>
<tr class="product-sample-field appended3">...</tr>

And so forth.

So I'm trying to grab all instances of .product-sample-field and .appended where .appended is dynamically getting a number appended to the class name.

CodePudding user response:

This returns all instances under .product-sample-field and class names start with "appended". Use * instead of ^.

$(".product-sample-field[class*='appended']");
  • Related