Check if checkbox is checked

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	$("#widen").attr('disabled', true);
	if ($('#ads').checked = true) {
		alert('ok');// not work
	}
});
</script>
</head>

<body>

<div><input type="checkbox" id="ads" /><label for="ads"> Hide ads.</label></div>
<div style="padding-left:20px">
	<input type="checkbox" id="widen" /><label for="widen"> Widen message aera to fit window</label>
</div>
</body>
</html>

I don’t know why my check function doesn’t work. Can you see it for me ?

function alert() works fine when tested alone. Infact so far, every scripts I’ve worked on run just fine except this “check checkbox” function. So there wouldn’t be js problem on browsers.

Gosh, this is driving me nut, it took me 3 hour already.

It works for me. In fact, with the assignment operation, you’d get the value of the left operand anyway. There’s an issue on your end that we aren’t seeing. Try a regular alert outside of all of your jQuery code.

Are you sure, derfleurer ? Both of yours dont work. Did you test it ?

= is an assignment operator. Use ==

if ($(‘#ads’).checked == true)

But to cut out the redundancy, just use:

if ($(‘#ads’).checked)

I finally got it work.

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
//	$("#widen").attr('disabled', true);
//	if ($('#ads').checked == true) {
//		alert('ok');// not work
//	}
	
	ads = $('#ads');
	ads.change(function(){
	  if ($(this).attr('checked') == true)
	  {
			alert('god damn');
	  }
	});
});
</script>
</head>

<body>

<input type="checkbox" id="ads" /><label for="ads"> Hide ads.</label>
<input type="checkbox" id="widen"  /><label for="widen"> Widen message aera to fit window</label>
</body>
</html>

What got in my chest is though, I still can’t figure out why the first snippet works for every body but me.