I have CSS in Style tag on the html header. What I want is that thru javascript to access all the classes of Style tag and check whether it has font-weight:bold or not; at the end I want an array of classes with font-weight:bold so that I can assign id attribute to them in javascript later.
CSS
span {
white-space: pre-wrap;
}
.pt-Normal {
line-height: 107.9%;
margin-bottom: 8pt;
font-family: Ca**strong text**libri;
font-size: 20pt;
margin-top: 0;
margin-left: 0;
margin-right: 0;
}
.pt-DefaultParagraphFont-000000 {
font-family: Calibri;
font-size: 11pt;
font-style: normal;
font-weight: bold;
margin: 0;
padding: 0;
}
.pt-DefaultParagraphFont-000001 {
font-family: Calibri;
font-size: 20pt;
font-style: normal;
font-weight: bold;
margin: 0;
padding: 0;
}
.pt-Normal-000002 {
line-height: 107.9%;
margin-bottom: 8pt;
font-family: Calibri;
font-size: 11pt;
margin-top: 0;
margin-left: 0;
margin-right: 0;
}
.pt-DefaultParagraphFont-000003 {
color: #FF0000;
font-family: Calibri;
font-size: 11pt;
font-style: normal;
font-weight: bold;
margin: 0;
padding: 0;
}
JAVASCRIPT from where I want to access the CSS class attribute.
//this is just example of one class having fontWeight:bold, but i want to do this in a generic way.
function sec(){var s = document.getElementsByClassName("pt-DefaultParagraphFont-000001");
for (var z = 0; z <= s.length;z++){s[z].setAttribute("id",z.toString());}}
var sc = document.getElementsByTagName("STYLE").style;
if (sc.fontWeight == bold){
//here i want to get all the class which have class attribute fontWeight:bold
//later on i want to assign id attribute to those elements which have fontWeight:bold
}
document.styleSheetsbut you'll miss the browser's defaults like<strong>nodes, so maybe you'd still be better to simply loop through all elements and check theirgetComputedStyle(el).fontWeight...document.styleSheetsordocument.style. @Kaiido @ZPiDER