mardi 18 juillet 2017

Checkbox manipulation with javascript/jquery

Hello I have a problem with checkboxes in my app. I want to set value of layer visibility to false when other layer visibility is true and also set checkbox value to checked when visibility of layer is true. I have problem with .click function - console throws me typeError checkbox[i].click is not a function.

var changeLayer = function() {
    if (layers[0].M.visible == true) {
        layers[1].M.visible == false
    } else if (layers[0].M.visible == false) {
        layers[1].M.visible == true
    }
    if (layers[1].M.visible == true) {
        layers[0].M.visible == false
    } else if (layers[1].M.visible == false) {
        layers[0].M.visible == true
    }
}

var checkbox = $('.layer');
for (i = 0; i < checkbox.length; i++) {
    checkbox[i].click(changeLayer);
//$(checkbox[i]).on('click', changeLayer)
}

Here is image of layer switcher where after click on first layer, second one should hide and uncheck the box.

Map layer switcher

I know that is maybe silly question, but I couldn't find solution. I hope you can help me.




Aucun commentaire:

Enregistrer un commentaire