So I just started trying to learn jQuery an hour or so ago, and I’ve got this code
Just trying to work out why the $(".actions .readbody").click(...) line doesn’t seem to be working.
I originally had this working where all the buttons were in a < ul > instead of a < div > (and each button had its own < li >). The readbody class got added to the Read body button’s < li > instead of directly to the button. The problematic line was more like $(".actions li.readbody button").click(...).
The full code is posted on jsfiddle: http://jsfiddle.net/J6u5X/
I jsFiddled your example – it is much easier to … fiddle with the code this way. See http://jsfiddle.net/v7ayc/
First thing I noticed is the
=operator in thewhileloop your click handler, I guess you meant==.Anyway, replacing the body of the function with the following code toggles the content:
$(this).parent('.actions').siblings('.body').toggle();Generally speaking, jQuery offers much easier and readable ways of traversing the DOM. Feel free to use it instead of the standard DOM interface.