This is a code which has 3 buttons (each called #make_post_X
) and once clicked on each it will do some stuff and then have the same code - check if what was clicked had active
class, and if not it will make it active while making other buttons inactive
$('#make_post_event').live('click', function(){
$('.new_post #post_type').val('event');
$('.event_fields').toggle();
var active = $(this).hasClass('active');
$(".post_options").removeClass('active');
if (!active){
$(this).addClass('active');
}
});
$('#make_post_image').live('click', function(){
$('.new_post #post_type').val('image');
$('.event_fields').hide();
var active = $(this).hasClass('active');
$(".post_options").removeClass('active');
if (!active){
$(this).addClass('active');
}
});
$('#make_post_video').live('click', function(){
$('.new_post #post_type').val('video');
$('.event_fields').hide();
var active = $(this).hasClass('active');
$(".post_options").removeClass('active');
if (!active){
$(this).addClass('active');
}
});
How can i put this code
var active = $(this).hasClass('active');
$(".post_options").removeClass('active');
if (!active){
$(this).addClass('active');
}
in a function which I would be able to call from each live click
?