javascript - jQuery Click function doesn't work on first child -
jQuery's click function is not working on Lee's first child
& Lt; Ul class = "clearfix" & gt; & Lt; Li class = "contracted" & gt; & Lt; A href = "#" & gt; & Lt; Span & gt; L1 & lt; B & gt;: Identify a number 10 times the value of & lt; / B & gt; & Lt; / Span & gt; & Lt; / A & gt; & Lt; / li & gt; & Lt; li class = "" & gt; & Lt; A href = "#" & gt; & Lt; Span & gt; L2 & lt; B & gt;: Identify a number, value of 10 times value & lt; / B & gt; & Lt; / Span & gt; & Lt; / A & gt; & Lt; / li & gt; & Lt; / Ul & gt; I also tried to move down the function below. But it is not working. The full working example is given in JSField.
$ ('contracted'). Click (function () {$ (this) .Parent (). Attr ('class', 'expanded' $ ('Ul.expanded li.activeLesson'). Attr ('class', 'selected'); $ ( 'Ul.expanded li: not (selected)'). Attr ('class', '');});
Your $ ('contracted'). Click (...) code will bind any element with one click handler to that class Runs that code at the moment - It will not automatically work on other elements which have been added later in the class if you want to work on any Li element If there is a contracted class at the time of the click, use a delegate event handler set through .on () : $ ('ul'). ('Click', 'li.contracted', function () {...}); This click handler is sent to all < Code> ul , but then when one click is checked in jQuery, if clicked item ul matches the selector in the second argument and only your function If you call The bit.
Comments
Post a Comment