lundi 2 mai 2016

Click on checkbox label not working

I have a checkbox inside a P with class vertical options. I have written script to implement checkbox functionality even on clicking the P. The code is:

$(".vertical-options,.horizontal-options").click(function(event){
    var input = $(this).find('input').first();
    console.log(input);
    if((event.target.type !== 'checkbox') && (input.attr('type') === 'checkbox')) {
        if(input.is(':checked')){
            input.prop('checked', false);
        } else {
            input.prop('checked', true);
        }
    }

    if((event.target.type !== 'radio') && ( input.attr('type') === 'radio')) {
        input.prop('checked', true);
    }               
    var optionsFormId = $(this).parent().attr("id");
    $("#"+optionsFormId+" p").removeClass("selectedOption");
    $(this).addClass("selectedOption");
 });

but with this logic clicking on the checkbox label does not work. What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire