Reputation: 2871
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';
}
Upvotes: 2
Views: 9603
Reputation: 9546
//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>
Upvotes: 2
Reputation: 82241
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';
}
Upvotes: 0