how to prevent buttons with same class from executing at the same time with jquery -
This can be a simple question once again, but I'm already spending a few hours already, So if you can help, I would greatly appreciate it.
I have a script that creates a list of applicants for a certain group. Every applicant has a few brief information about him, his "small business card" has two buttons on the business card; 1 was placed on the shortlist and the candidate rejected the application. The problem is that once you click on a Shortlist button, the jquery code runs on all buttons in the list. This is understandable because they all are the same class (button 15) because the PHP is generated in the variable except it does not add selected, but the candidate for at least shortlist.
What would I want to know when how do I stop all the buttons running the code when I click on a button? Here is the code that generates this accident:
$ (document) .ready (function () {$ ('15 buttons). Click (function (e) {$ .ajax ({Type: "POST", url: "shortlist.php? U = & php; echo $ _applicant ;? & gt; & N = & lt; php echo $ _name;? & Gt; amp = H = & lt ;? php echo $ _colhead;? & gt; data: "data string", before: function () {var exhtml = $ ('.msg'). html (); $ (' .msg ') .html ("& lt; img src =' .. / images / animated GIF tapbar ./gt;"). Delay (1000);}, success: function (html) {var responsetext = "& Lt ;? php echo $ _applicant ;; & gt; "$ ('.15'). Feeds (" slow "); $ ('. Button 14'). Feet (" Security "); $ ( '. Msg'). Html (responsible) delay (800) Kfedin (" slow ");}});});}); Any help would be greatly appreciated. thank you in advanced!
Edit This is the correct code:
$ (document) .ready (function ($. 15 '). Click (function (e) {var self = this; var a = ($ (this) .attr (' id ')); $ .ajax ({type: "POST", "shortlist" Php? U = "+ a +" & amp; n = & lt ;? php echo $ _name;? & Gt; & amp; HK = & lt ;? php echo $ _colhead ;? & gt; ", data: Datastring ", before: function () {var exhtml = $ ('.msg') .HTML (); $ (self) .siblings ('.msg') .html (" & lt; img src = 'http: // files.domain.com/images/animated gif tapebar.gif '/ & gt; "). Delay (1000);}, success: function (html) {var responsetext =" You successfully completed "+ a +" in the shortlist Added $ (self $ ('Slow'); $ ('slow'); $ (self). Sibing ('.msg') .html (responsetext) .Fadeine ("slow"). ;}});});});
If I understand correctly If you want to work with only your existing elements all the buttons disappear 15 elements.
Try to refer to the current element like this:
var self = this; and use it in the success function:
$ (document) .ready (function () {$ ('. Button15'). (Function (e) {var self = this; $ .xx ({type: "post", url: "shortlist.fip? U = But I do not know that there are button14 and msg elements ... I think they are also connected to the current element ... Edit
Instead of changing all msg elements, get the brother of an existing element using only $ (self) Are there. ('.msg') ; In response the code was changed accordingly.
Comments
Post a Comment