Hi,
I have a small script that I wrote in jQuery and I would like to convert it to vanilla javascript so I can ditch jQuery for pages that use this script.
jQuery(document).ready(function($) {
$(document).on('click', '.wpstp_button_follow', function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: ajaxurl+"?action=wpstp_follow",
data: $('#wpstp_form').serialize(),
dataType: "text",
success: function(response) {
var count = Number($(".follow_count").text());
var newCount = count + 1;
console.log(newCount);
$('.follow_count').text(newCount);
$(".follow_text").text("Unfollow");
$("#follow_button").removeClass("wpstp_button_follow");
$("#follow_button").addClass("wpstp_button_unfollow");
}
});
});
$(document).on('click', '.wpstp_button_unfollow', function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: ajaxurl+"?action=wpstp_unfollow",
data: $('#wpstp_form').serialize(),
dataType: "text",
success: function(response) {
var count = Number($(".follow_count").text());
var newCount = count - 1;
console.log(newCount);
$('.follow_count').text(newCount);
$(".follow_text").text("Follow");
$("#follow_button").removeClass("wpstp_button_unfollow");
$("#follow_button").addClass("wpstp_button_follow");
}
});
});
});
How would this be converted to use vanilla js?