I want to get a specific parent node of an element use jQuery but it's not working for some reason -
I have a span inside a legend tag that I want to use to remove the field tags when I click. I am using jQuery and this is the code that I can not seem to work on: (Yes, I am using the latest version of jQuery)
jQuery:
function removeStep () {$ (this) .closest ("fieldset"). Remove (); // Already attempted: $ (this) .parents ("field"). Remove (); . . . Did not work}} HTML:
& lt; Div id = "steps" & gt; & Lt; Fieldet class = "step" & gt; & Lt; Legend & gt; STEP 1: & lt; Span class = "remove" onclick = "removeStep ();" & Gt; Remove & lt; / Span & gt; & Lt; / Legend & gt; & Lt; / Fieldset & gt; & Lt; / Div & gt;
The problem is that "this" in your function may not be as intended .
Since you are using jQuery anyway, you should go straight through the HTML markup using the habit of berting event handlers directly. Instead, set up the handler with jQuery:
$ (function () {$ ('span.remove'). Click (stop stop);}); If you should do this in HTML then try this:
...
Comments
Post a Comment