Open In App

SVG Event.defaultPrevented Property

Last Updated : 30 Mar, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The SVG Event.defaultPrevented property returns a Boolean value indicating whether the call to Event.preventDefault() canceled the event.

Syntax:

var defaultWasPrevented = event.defaultPrevented

Return value: This property returns the boolean value of the event element.

Example 1: In this example, we will use onclick event.

html
<!DOCTYPE html>
<html>

<body>
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg">
        
        <circle cx="50" cy="50" r="50" 
            onclick="check(event)" />

        <script type="text/javascript">
            function check(event) {
                document.write(
                    "This Event is defaultPrevented : ", 
                    event.defaultPrevented);
            }
        </script>
    </svg>
</body>

</html>

Output:

Example 2: In this example, we will use onclick event.

html
<!DOCTYPE html>
<html>

<body>
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg">
        
        <text x="50" y="20" font-size="20px"
            onclick="check(event)">
            GeeksForGeeks
        </text>
        
        <script type="text/javascript">
            function check(event) {
                document.write(
                    "This Event is defaultPrevented : ",
                    event.defaultPrevented);
            }
        </script>
    </svg>
</body>

</html>

Output:

Example 3: In this example, we will use onmouseover event.

html
<!DOCTYPE html>
<html>

<body>
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg">
        
        <circle cx="50" cy="50" r="50" 
            onmouseover="check(event)" />

        <script type="text/javascript">
            function check(event) {
                document.write(
                    "This Event is defaultPrevented : ", 
                    event.defaultPrevented);
            }
        </script>
    </svg>
</body>

</html>

Output:

Example 4: In this example, we will use onmouseover event.

html
<!DOCTYPE html>
<html>

<body>
    <svg viewBox="0 0 1000 1000" 
        xmlns="http://www.w3.org/2000/svg">
        
        <text x="50" y="20" font-size="20px" 
            onmouseover="check(event)">
            GeeksForGeeks
        </text>
        
        <script type="text/javascript">
            function check(event) {
                document.write(
                    "This Event is defaultPrevented : ",
                    event.defaultPrevented);
            }
        </script>
    </svg>
</body>

</html>

Output:


Explore