Open In App

HTML | DOM Base target Property

The Base target Property in HTML DOM is used to set or return the value of the target attribute of a <base> element. The target attribute is used to specify the default target for all hyperlinks and forms in the page. 

Syntax: 



baseObject.target
baseObject.target = "_blank|_self|_parent|_top|framename"

Property Values: 

Return Value: It returns a string value which represents the default target for all hyperlink and forms in the page. 



Example 1: This example returns the base target Property. 




<!DOCTYPE html>
<html>
<head>
    <base id="Geek_Base"
        href="https://www.geeksforgeeks.org" target="_self">
    <title>
        HTML | DOM Base target Property
    </title>
</head>
<body style="text-align:center;">
    <h1 style="color:green;">
            GeeksForGeeks
    </h1>
    <h2>HTML | DOM Base target Property</h2>
    <button onclick="myGeeks()">
        Click
    </button>
    <h4 id="Geek_p" style="color:green;font-size:24px;"></h4>
     
    <!-- Script to return DOM Base target Property -->
    <script>
        function myGeeks() {
             
            var x = document.getElementById("Geek_Base").target;
             
            document.getElementById("Geek_p").innerHTML = x;
        }
    </script>
</body>
</html>

Output: 

Before Clicking on Button:

  

After Clicking on Button:

  

Example 2: This example sets the base target Property. 




<!DOCTYPE html>
<html>
<head>
    <base id="Geek_Base" href=
    "https://www.geeksforgeeks.org" target="_self">
    <title>
        HTML | DOM Base target Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1 style="color:green;">
            GeeksForGeeks
    </h1>
    <h2>HTML | DOM Base target Property</h2>
    <button onclick="myGeeks()">
        Click
    </button>
    <h4 id="Geek_p" style="color:green;font-size:24px;"></h4>
     
    <!-- Script to set DOM Base target Property -->
    <script>
        function myGeeks() {
  
            var x = document.getElementById("Geek_Base").target
                = "_blank";
             
            document.getElementById("Geek_p").innerHTML
                = "The value of the target attribute was "
                + "changed to " + x;
        }
    </script>
</body>
</html>

Output: 

Before Clicking on Button: 

 

After Clicking on Button:

  

Supported Browsers: The browser supported by DOM base target property are listed below:


Article Tags :