admin管理员组文章数量:1315807
I'm trying to make the text of a button bee 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';
}
I'm trying to make the text of a button bee 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
http://jsfiddle/14tjwvnq/
function boldButton(){
$('#btn').style.fontWeight = '700';
}
Share
Improve this question
edited May 23, 2017 at 12:10
CommunityBot
11 silver badge
asked Jan 6, 2015 at 13:02
CaraselCarasel
2,8715 gold badges33 silver badges53 bronze badges
3
- what should be the behavior when you click it again ? do you need the Bold to be temporary (sec, while holding the mouse down), to taggle on each click , or just to stay bolded after the first click. – d.raev Commented Jan 6, 2015 at 13:06
- I need it to stay bold after the first click. – Carasel Commented Jan 6, 2015 at 13:21
- your example gets error "ReferenceError: boldButton is not defined" as the function is not defined on after the HTML is rendered. Move the function in the header, or use some selector to assign the ONCLICK to the buttons onLoad. – d.raev Commented Jan 6, 2015 at 13:27
3 Answers
Reset to default 4In jQuery you need to use css
method:
$('#btn').css( 'font-weight', '700' );
jsFiddle
YOU MIGHT NOT NEED JQUERY
//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>
fiddle
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';
}
Working Demo
本文标签: javascriptChange button text to bold on clickStack Overflow
版权声明:本文标题:javascript - Change button text to bold on click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741989197a2408867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论