This article introduces how to solve jquery TypeError: this. parentnode is undefined when using JQuery parentNode. For more information, see.
The error message is as follows:
The Code is as follows: |
Copy code |
JQuery TypeError: this. parentNode is undefined $ (". Btn-add"). click (function (){ Var td = $ (this). parent (). parent (); $. Ajax ({ Url: Drupal. settings. basePath + 'ajax/quiz_type/change ', DataType: 'json ', Data: 'quiz _ type_id = '+ td. find (". quiz_type_id"). val () +' & answer_id = '+ td. attr ('attr '), Type: "POST ", Success: function (output ){ If (output. data ){ If ($ ('. message', td). length> 0 ){ $ ('. Message', td).html (output. data ); } Else { // $ (This). after ('<div class = "message">' + output. data + '</div> '); Td. append ('<div class = "message">' + output. data + '</div> '); } } If (output. status & output. quiz_type ){ Td. find (". quiz_type" pai.html (output. quiz_type ); Td. find (". quiz_type_id_edit"). hide (); Td. find (". add-btn"). hide (); Td. find (". quiz_type"). fadeIn (); Td. find (". edit-btn"). fadeIn (); } } }); Return false; }); |
Solution
In the ajax return judgment, an error occurs when $ (this). after is used in Firefox. The problem is solved by modifying it to the object td defined outside ajax.