Link to home
Start Free TrialLog in
Avatar of usmbay
usmbayFlag for United States of America

asked on

Change font using a checkbox

Hello,

I want to change the font to strong if the checkbox checked

<input type="checkbox" name="isDefaultTemplate" value="DefaultTemplate"  This a default template>    
Avatar of frin
frin
Flag of Slovenia image

This code will change whole document's font to bolder (strong) when checkbox is checked, or unchange if it's not checked:

<script>
function change(value) {
  if(value) document.body.style.fontWeight = 'bolder';
  else document.body.style.fontWeight = '';
}
</script>
<input type="checkbox" onchange="change(this.checked)" name="isDefaultTemplate" value="DefaultTemplate">  This a default template
Avatar of usmbay

ASKER

Thanks but I want it for this phrase only " This a default template "
Oh okay, this then:

<script>
function change(value) {
  if(value) document.getElementById('content').style.fontWeight = 'bolder';
  else document.getElementById('content').style.fontWeight = '';
}
</script>
<input type="checkbox" onchange="change(this.checked)" name="isDefaultTemplate" value="DefaultTemplate">  <div id="content">This a default template</div>
Avatar of usmbay

ASKER

ok it changs the font but not dynamic, I mean I have to click on the text to be changed
ASKER CERTIFIED SOLUTION
Avatar of frin
frin
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of usmbay

ASKER

Excellent, Thanks