jQuery click function vs inline onclick -
I am trying to reconfigure my code and make it more careless.
Mainly, a link to an action if you click on the link, action is taken through AJAX (the AJAX code is not on the code here) and the text is replaced by the second lesson , Which gives the user the ability to undo the operation. If the user clicks on the previous link, then Ajax restores the previous state and shows the text that he performs the work shown to the user again.
I have the same HTML file (code below) of my problem. There are two paragraphs if you click on the first paragraph link, which uses inline onclick calls, the code works as expected, but if you click on the link of the second paragraph, which uses the jQuery onclick function So, the undo link is not working, and I do not know why.
Any help? Thanks a lot!
& lt ;! DOCTYPE html public "- // W3C // DTT XHTML 1.0 Strongly // n" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" & gt; & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en" lang = "en" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; & Lt; / Title & gt; & Lt; Script src = "http://code.jquery.com/jquery-latest.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; $ (Function () {$ (". Add2") (function () {var placeId = $ (this) .parents (". Place"). Attr ("id"); $ ("#" + placeId + ".add2") Remove (); $ ("#" + location id + "action."). Attachment ("& lt; span class = \" added \ "& gt; added! & Lt; / Span & gt; & lt; a click (function {} {var placeId = $ (this)) = $ (".addoadd2". ("Span.added, a.add2"). ($) "$" (".", "$" # "+ PlaceId +". ") .andend (" & lt; a square = 'ad2' onclick = 'copyPlace (\ "" + placeId + "\"); return returned ;;); Addplace (placeId); $ {"(" # "+ location id +" .add "); add & quot;; href = '#' & gt; place & lt; / a & gt; ). Remove (); $ ("#" + Location id + "actions."). The attachment ("& lt; span class = \" added \ "& gt; added! & Lt; / span & gt; & lt; one class = \" undoadd \ "href = \ "# \" Onclick = \ "undoAddPlace ('" + + Location ID + "'); Return Back; \" Undo & lt; / a & gt; "); Description is False;} Function UndoPlace (Location ID) {$ ("#" + Location ID + "Responses"). Search ("span.added, a.undoadd"). Remove (); $ ("#" + Location ID + "actions"). Attachment ("& lt; a class = 'plus' onclick =' adepass (\" "+ location id +" \ "); return return;; href = '#' & gt; add place & lt; / a & gt ; "); return false; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body id = "home" & gt; & Lt; Div class = "location" id = "3435 910" & gt; & Lt; P class = "actions" & gt; & Lt; A href = "#" onclick = "ad place ('3435 910'); return false;" Class = "add" & gt; Add place & lt; / A & gt; & Lt; / P & gt; & Lt; / Div & gt; & Lt; Div class = "location" id = "3435912" & gt; & Lt; P class = "actions" & gt; & Lt; A href = "#" class = "add2" & gt; Add place & lt; / A & gt; & Lt; / P & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Since you are dynamically adding new items to the DOM, You can use
for it.
Update
Since jQuery 1.7, the method is the preferred method of doing this.
The method has been removed from jQuery 1.9.
Comments
Post a Comment