Supongamos este código:
jQuery(function($) { $(document).find('.answer-choice').on('click', function() { $(this).addClass('loading-gif'); var form = $('form#submit_quiz'); var quiz = form.find('input[name="quiz"]').val(); var ticket = form.find('input[name="ticket"]').val(); var _wpnonce = form.find('input[name="ticket_nonce"]').val(); $.ajax({ url: public_quiz_participation.ajax_url_answer_question, method: 'post', //dataType: 'json', data: { action: 'lottery_answer_question', status: 'answered_question', quiz: quiz, ticket: ticket, question: $(this).data("question"), answer: $(this).data("answer"), _wpnonce: _wpnonce }, success: function(response) { console.log($(this)); // Here, among some other things, I want to 1. remove the class 'loading-gif' from the choice the user clicked, and 2. (with the help of some DOM tree traversing) add a 'disabled' class to that answer and the rest choices (its siblings) of the particular question. Part 2. is actually easy enough. My problem is that $(this) isn't available anymore to the success event function. }, error: function() { swal.fire({ type: 'info', html: "<h2>" + quiz.loadResource + "</h2><br><h6>" + quiz.somethingWentWrong + "</h6>" }); } }); }); });Básicamente, mi pregunta está en un comentario en el código anterior, pero también lo estoy pegando a continuación, para que sea más legible:
Aquí, entre algunas otras cosas, quiero 1. eliminar la clase 'loading-gif' de la opción en la que hizo clic el usuario, y 2. (con la ayuda de algunos recorridos del árbol DOM) agregar una clase 'deshabilitada' a esa respuesta y el resto de opciones (sus hermanos) de la pregunta en particular. La parte 2 es bastante fácil. Mi problema es que $(this) ya no está disponible para la función de evento de éxito.
Entonces, ¿cómo puedo pasar $(this) como una variable a la función del evento de éxito?