I'm trying to make the text of a button become bold when it is clicked on. I have tried using the advice from this question: How to make a text in font/weight style bold in JavaScript
function boldButton(){
$('#btn').style.fontWeight = '700';
}
//Inline
<button class="btn" id="btn1" onclick="this.style.fontWeight = 'bold'">Test1</button>
//OR with function
<button class="btn" id="btn2" onclick="boldButton(this)">Test2</button>
<scrypt>
function boldButton(btn){
btn.style.fontWeight = '700';
}
</scrypt>
You need to convert jquery object to javascript object before setting the property through javascript. also make sure that onclick method is defined :
function boldButton(num){
$('#btn'+num)[0].style.fontWeight = '700';
}
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.