So I have this css:
tag[class*="samepart-"] {
/* css code for all html classes with "samepart-" in their class name */
}
With this html:
<div class="samepart-a">some html a</div>
<div class="samepart-b">some html b</div>
<div class="samepart-c">some html c</div>
Now I want to get all the html classes with "samepart-" in JS without adding an extra html class to the "samepart-" classes.
This is what I tried:
const htmlClasses1 = document.getElementsByClassName("samepart-");
console.log(htmlClasses1[0]);
const htmlClasses2 = document.getElementsByClassName('*["samepart-"]');
console.log(htmlClasses2[0]);
const htmlClasses3 = document.getElementsByClassName('[class*="samepart-"]');
console.log(htmlClasses3[0]);
const htmlClasses4 = document.getElementsByClassName(["samepart-"]);
console.log(htmlClasses4[0]);
div[class*="samepart-"] {
display: inline-block;
width: 120px;
height: 120px;
background-color: #00F;
color: #0FF;
}
<div class="samepart-a">some html a</div>
<div class="samepart-b">some html b</div>
<div class="samepart-c">some html c</div>