I am now searching for hours for this simple answer. I have 5 upload fields for images and I want to create a Delete button for each uploaded image. If you click on this button, then you have to remove the nearest image.
I know that there are so many questions about this item on the stack, but can not get it right. I've tried to the nearest ()
, search ()
, closest ()
with children ()
But can not do it
Can someone give me the correct sign?
I created a JSField:
This is my html:
& lt; Div class = "stn_uploader" & gt; & Lt; P class = "delete" & gt; Remove & lt; / P & gt; & Lt; Img src = "http://3.bp.blogspot.com/-hME1fzYTKkc/Tl157uRJ3gI/AAAAAAAAIzQ/OnqAvShajaLA/s1600/white-clouds.jpg" width = "300" /> & Lt; / Div & gt; & Lt; Div class = "stn_uploader" & gt; & Lt; P class = "delete" & gt; Remove & lt; / P & gt; & Lt; Img src = "http://3.bp.blogspot.com/-hME1fzYTKkc/Tl157uRJ3gI/AAAAAAAAIzQ/OnqAvShajaLA/s1600/white-clouds.jpg" width = "300" /> & Lt; / Div & gt; & Lt; Div class = "stn_uploader" & gt; & Lt; P class = "delete" & gt; Remove & lt; / P & gt; & Lt; Img src = "http://3.bp.blogspot.com/-hME1fzYTKkc/Tl157uRJ3gI/AAAAAAAAIzQ/OnqAvShajaLA/s1600/white-clouds.jpg" width = "300" /> & Lt; / Div & gt;
This is my jquery:
$ (document) .ready (function () {$ ('. Stn_uploader .delete'). Function () {$ (This) .clostest ('.img'). Remove ();});});
Image is brother so that will not work ()
. You can use
$ (document) .ready (function () {$ ('.stn_uploader .delete'). Click (function () {$ (this) .next ('img'). Remove ();});});
$ {document} .ready (function () {$ (' .stn_uploader .delete '). Click (function () {$ (this) .closest (' .stn_uploader '). (' Img '). Remove ();});});
Comments
Post a Comment