Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140012

undefined value from return - event

$
0
0

I would like to return from the function of an event some value. Bellow, you can find html and js where I've put a button. I would like to have an output true or false. I have only information about event type in the console but I do not know how to put true or false value outside the function to a variable (or to another function - I would like to make of this information as a parameter in a different place).

<body class="container">
     <button class="button">Click me</button>

     <script src="app.js"></script>
    </body>
    document.addEventListener("DOMContentLoaded", function() {
        function clickFunct(e){
            if(e.target.classList.contains("button")){
                console.log(e.type);
                return true
            }
            else{
                console.log("to nie przycisk")
                return false
            }
        }
        document.addEventListener("click", clickFunct);
        })
    });

I've removed "my tries" from code to have transparent code.


Viewing all articles
Browse latest Browse all 140012

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>