$('.classToClick').live("click", function () {
$(this).attr('disabled', 'disabled');
$(this).val("lol");
$.post('post.php', {
string: "lalala"
}, function (data) {
$(this).removeAttr('disabled');
});
})
This code doesn’t work, because in post we use $(this). When we change it to .classToClick, it works.
How can we get the class of the element clicked so that we could use it like this?
$('.classToClick').live("click", function () {
var className = $(this).name;
$(this).attr('disabled', 'disabled');
$(this).val("lol");
$.post('post.php', {
string: "lalala"
}, function (data) {
$(className).removeAttr('disabled');
});
})
Is it possible to do something similar?
Upon clicking, you will need to capture the class name, which can be done via:
and when you later refer to it inside of the $ selector, you need to include the period to denote a class is being selected, as such:
Code:
Working Example