Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Help: using jquery checkbox

jQuery jquery

  • Please log in to reply
1 reply to this topic

#1 wheay


    CC Regular

  • Member
  • PipPipPip
  • 33 posts

Posted 21 December 2011 - 09:13 PM

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.
  • 0

#2 RhetoricalRuvim


    JavaScript Programmer

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1311 posts
  • Location:C:\Countries\US
  • Programming Language:C, Java, C++, PHP, Python, JavaScript

Posted 21 December 2011 - 10:40 PM

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
  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download