Library/jQeury

jQuery - preventdefault

청렴결백한 만능 재주꾼 2021. 2. 24. 00:48
반응형
<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <link rel="stylesheet" href="style.css">
    <script type="text/javascript">
        $(document).ready(function () {
            $('#myHyperLink').on('click', function (e) {
                e.preventDefault();
                $('#divResult').append('Hyperlink default action prevented<br/>');
            });
        });
    </script>

</html>head>

<body>
    <a id="myHyperLink" href="http://google.com">
        Clicking here does not take you to google
    </a>
    <div id="divResult"></div>
</body>
</html>

기본 기능을 막는 메소드.

반응형