Hi im newbies in jquery, i want to use checkbox to create a font styling effect.
i have a div that shows the input text.
the checkbox indicates bold, italic and underline.
how do i do that?
can you show it also using radio button?
thank you.
1 reply to this topic
#1
Posted 21 December 2011 - 09:13 PM
|
|
|
#2
Posted 21 December 2011 - 10:40 PM
You'll need to use the Element.checked property.
If the checkbox is checked, the Element.checked property will be 'true' , otherwise it would be 'false' .
Take a look at the following:
Or you could programmatically change the state of the checkbox, such as this:
As for the styling, you can use the style object. So if you have an HTML element like this:
Also, Element.style.textDecoration is for underlining, while Element.style.fontStyle is for italicizing.
Here's more reference to the style object:
HTML DOM Style object
<input type="checkbox" id="chk1" /> This is a checkbox...
If the checkbox is checked, the Element.checked property will be 'true' , otherwise it would be 'false' .
Take a look at the following:
if ($("#chk1").checked == true) alert ("The checkbox is checked.");
else alert ("The checkbox is not checked.");
Or you could programmatically change the state of the checkbox, such as this:
$("#chk1").checked= true; , or also uncheck the checkbox: $("#chk1").checked= false;
As for the styling, you can use the style object. So if you have an HTML element like this:
<div id="txt">Some text...</div>, you can programmatically change the style using the style object:
$("#txt").style.color= "#FF0000";
$("#txt").style.fontFamily= "Times New Roman";
$("#txt").style.fontSize= 12;
$("#txt").style.fontWeight= "bold"; // This is from what I can recall.
Also, Element.style.textDecoration is for underlining, while Element.style.fontStyle is for italicizing.
Here's more reference to the style object:
HTML DOM Style object
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









