You can use document.querySelector
to get elements on the page, with attribute selector. querySelector
and querySelectorAll
accepts CSS selectors like jQuery.
console.log(document.querySelector('[class*="sample-row"] .co-1').innerText)
console.log(document.querySelector('[class*="sample-row"]').className.replace(/sample-row-/, ''))
<div class="sample-row-xxxxxx">
<div class="co-1 xxxxxxx">value</div>
</div>
the selector will find any element that have sample-row
somewhere inside class attribute that have .col-1
element inside.
If you’re know for sure that is at the beginning of the class you can use [class^="sample-row"]
selector instead but you can have other classes before sample-row.
solved Obtain the value variable [closed]