Lukas Baliƫnas Lukas Baliƫnas - 6 months ago 25
Javascript Question

Event when a pair of elements are clicked

I have 5 elements with class

and unique id's, and a button with class
. When
is clicked after
and vice versa, a function should be executed. I don't know what jQuery method i should use.


Try this :

<!DOCTYPE html>
        .active {
            background-color: skyblue;
        <div class="home">I am Div1</div>
        <div class="home">I am Div2</div>
        <div class="home">I am Div3</div>
        <div class="home">I am Div4</div>
        <div class="home">I am Div5</div>
        <button class="btn">Run</button>
    <script src=""></script>
            var divReady = false;
            var btnReady = false;
                btnReady = true;
                if (divReady)
                divReady = true;
                if (btnReady)
            function fun() {
                alert("I am working!")
                btnReady = false;
                divReady = false;