Reputation: 73908
I need change the font weight for a text element in JavaScript:
My code here does not work:
var btn = document.getElementById('accessibilityButton');
btn.innerHTML = 'Default Text';
btn.innerHTML.style.fontWeight = 'bold';
What am I doing wrong?
Please note that I don't want to use any libraries (jQuery et. al.) and am looking for a plain JS solution.
Upvotes: 7
Views: 64931
Reputation:
Keep 'return false' to prevent postback.
<button id="btn" onclick="this.style.fontWeight = 'bold';return false;" >TEXT</button>
Upvotes: 2
Reputation: 11812
You need to use:
btn.style.fontWeight = 'bold';
as it's a property of the element itself.
See: http://jsfiddle.net/6ypS8/
Upvotes: 19
Reputation: 1282
You should apply your style directly on your button not on button.innerHTML :
btn.style.fontWeight = 'bold';
Upvotes: 5