WebMasterCampus
WEB DEVELOPER Resources

jQuery Event preventDefault vs StopPropagation

jQuery Event preventDefault vs StopPropagation


preventDefault vs StopPropagation Example


    <div id="result">
        <a href="https://www.yahoo.com">www.Yahoo.com</a><br>
        <a href="https://www.bing.com">www.bing.com</a><br>
        <a href="https://www.google.com">www.google.com</a><br>
    </div>

    <script src="https://code.jquery.com/jquery-git.js"></script>
    <script>
        $("a").click(function(e){
            console.log("A Tag clicked");
             e.preventDefault();
             //e.stopPropagation();
            // return false;
        });

        $("#result").click(function(e){
            console.log("Div id result just clicked!!")
        });
    </script>
Created with love and passion.