Add JS variable to a class function?

Good day, the main problem of the weak knowledge of JS can't create matter, but will clearly show, there is such code:
$(".create-survey-question-button").on("click", function (event) {
event.preventDefault();
 var count = $(".count").val();
$.ajax({
 url: "/wp-admin/admin-ajax.php",
 method: 'post',
 data: {
 action: 'ajax_order',
 count: count
},
 success: function (response) {
$('#create-survey-question').html(response);
}
});
});


How to make so that to the class in functions added the value of the counter for example
$(".create-survey-question-button2").on("click", function (event) {
event.preventDefault();
 var count = $(".count").val();
$.ajax({
 url: "/wp-admin/admin-ajax.php",
 method: 'post',
 data: {
 action: 'ajax_order',
 count: count
},
 success: function (response) {
$('#create-survey-question2').html(response);
}
});
});

etc., the counter variable is transmitted from a hidden input field with the class .count and further increases the value there, i.e. it is sufficient to substitute the value
var count = $(".count").val();
in the right place but I can not understand how, understand that you need to declare the variable outside the function, but how then to add to the class?
Thanks in advance.
April 4th 20 at 00:49
0 answer

Find more questions by tags JavaScript