How to add toggleClass to a checked checkbox with jQuery?

This line: var elems = '' + '' + '' + ''; ...has two extra quotes. It should be: var elems = '' + '' + '' + ''; That breaks your selector for the click event. But note, that won't work anyway, since you are trying to hook an element that does not exist until the 'click me' link is pressed - so you need to use .live() or .delegate() for that anyway.

Something like this might work: $("#drag"). Delegate("inputtype=checkbox", "change", function(){ var index = this.id. Substring(8); $("#inputfield" + index).

ToggleClass("complete"); }).

– Opoe 7 Dec7 at 12:03 @Opoe: substring(8) converts an id like checkbox13 to 13 by removing the first 8 characters. – sje397 Dec 19 '10 at 12:05 @Opoe: I just made a small edit (removed '.' from start of 'complete') - oops. – sje397 Dec 19 '10 at 12:09 1 No - the event that is handled is the change of the checkbox - so inside the delegate function, this refers to the checkbox, so this.

Id is checkbox where n is the counter value. – sje397 Dec 19 '10 at 12:17 1 @Opoe: you can't have more than one element with a particular id. When you fix the quotes as mentioned at the top of my answer, each checkbox gets a new id with a number on the end.

#checkbox would only select the element with that particular id. And, delegate is (almost) always used with some kind of parent container (since it "delegates" the event handling). – sje397 Dec 19 '10 at 12:23.

You want: $('input:checkbox'). Click(function(){ $('#inputfield'). ToggleClass('bold'); }); I'm assuming you aren't setting your checkboxes' checked state to true dynamically.

– Phil. Wheeler Dec 19 '10 at 8:07 ofcourse thank you its in the OP – Opoe Dec 19 '10 at 11:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions