Jump to content

Help: using jquery checkbox

- - - - -

  • Please log in to reply
1 reply to this topic

#1
wheay

wheay

    Learning Programmer

  • Members
  • PipPipPip
  • 32 posts
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.

#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
You'll need to use the Element.checked property.

<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