I have an each function that has change function and ajax inside..
$( ".spring_explorations" ).each(function() {
$("#" + this.id + " select").change(function() {
alert("t");
$.ajax({
type: 'POST',
url: ('/admin/applications/get_sections_for_modal'), //pass query string to server
data: {
exploration_id: $("#" + this.id + " select").val()
},
success: function (response) {
$(this).parents('span').next().show();
$(this).parents('span').next().find("select").html(response);
console.log(response);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(thrownError);
}
})
});
});
I would like to access the $(this)
element of spring_explorations
class inside the success
snippet of ajax
script.
I was able to access the element of the change
function by adding context: this
but how can I get the element of the outer?
Thanks in advanced.
Edit:
The $(this).parents('span').next().show();
and so on are undefined because maybe the this
is the ajax itself not the spring_explorations
class.
I'm very sorry if this is a duplicated question. I'm just fairly new in javascript and I think this is the right place to ask this thing. If you think this is not appropriate, just close my question.