简体   繁体   中英

Cannot Set Property 'fontWeight' of undefined

Im trying to bold Student[i].club and I'm trying put a horizontal space between Student[i].gender and Student[i].grade. Each of the inputs goes into a div and displays in it. If the rest of the code is need I'll post that too if necessary.

Thanks in advance!

  fieldann += Student[i].grade; fieldann += Student[i].gender; fieldann += Student[i].club; fieldann += Student[i].announcement; Student[i].grade.style.fontWeight = "900"; var div = document.createElement("div"); div.style.width = "20%"; div.style.height = "100%"; div.style.background = "white"; div.style.color = "#202020"; div.style.border = "1px solid #202020"; div.align = "center"; div.style.marginLeft = "40%"; div.style.fontFamily = "Lato"; div.innerHTML = "<br>" + Student[i].club + "<br>" + "<br>" + Student[i].announcement + "<br>" + "<br>" + Student[i].gender + Student[i].grade + "<br>" + "<br>"; document.body.appendChild(div); 

Student[i].grade is not an HTML DOM element, so it does not have a style property and thus you can not set the fontWeight property.

Try setting this on a HTML DOM Element instead of string like:

div.style.fontWeight = "900";

Add student[i].club in a div and then set font weight to it.

"<br><div id='club'" +
Student[i].club +
"</div><br>" +
"<br>" +
Student[i].announcement +
"<br>" +
"<br>" +
Student[i].gender +
Student[i].grade +
"<br>" +
"<br>";


var club = document.getElementById('club');
club.style.fontWeight="bold";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM