Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to grab all instances of a class name

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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

$(".product-sample-field[class*='appended']");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading