lundi 3 octobre 2016

Observing two elements at a time

I have a list from which one can select one element at a time. I also have a checkbox. I want to display something, only, and only when the checkox is checked AND something from the selection list is picked. I also want to update the displayed stuff when someone picks a new element from the list or unchecks the checkbox. I am having trouble putting these two things together.

On the list with the possible selection I have click-Event

$(".selection").click(function() {
    $("#selectionText").text($(this).prop("innerHTML"));
});

The checkbox I can observe like this:

someCheckbox.addEventListener("change", function(e) {    
    // ...
});

What I cannot get my head around is: How to put these two events (click and change) together? When I put the jQuery click inside the change event, this ($("#selectionText").text($(this).prop("innerHTML"));) only gets executed when the status of the checkbox is changed. It does not get executed when the website firsts load, because the status of the checkbox did not change yet. Needless to say that it does not work the other way round (eventListener click inside jQuery change).

Aucun commentaire:

Enregistrer un commentaire