Problem on how to style the append element in javascript. How can style the elemnt that i bold in javascript? try to style it in the javascript but failed to. Can someone help me? How can style this part?
let contents = document.createElement('div');
contents.innerHTML = **val1.mail_no + ' - ' + val1.mail_subject;**
you can do it by updating style
attribute of contents
:
contents.style.fontWeight='bold'
document.getElementById( agency_${agoptions.ag_id}_${agoptions.ad_id}
).appendChild(contents).style.fontWeight = "900";
Here are couple of ways you can try
document.getElementById('one').innerHTML = '<b> Show as bold </b>'; document.getElementById('two').innerHTML = '<span style="font-weight: bold;"> bold again </span>';
<div id="one">x</div> <div id="two">y</div>
first of all try to avoid using javascript to style elements, but if you have to here is how to do it
method 1: declare a class in css
.bold{font-weight:bold;}
then add
document.getElementById("id of element").classList.add("bold");
method 2:
document.getElementById("id of element").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.