

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Anchor type Property
<p>The HTML DOM type property associated with anchor tag is used to set or get the value of the type attribute of the link. This attribute was introduced in HTML 5. This attribute is also for only suggestive reasons and isn’t compulsory to include. It contains single MIME(Multipurpose Internet Mail Extensions) value type.</p><h2>Syntax</h2><p>Following is the syntax for −</p><p>Returning the type property −</p><pre class="result notranslate">anchorObject.type</pre><p>Setting the type property −</p><pre class="result notranslate">anchorObject.type = MIME-type</pre><h2>Example</h2><p>Let us see an example for anchor text property −</p><p><a class="demo" href="http://tpcg.io/VAsVqK" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate"><!DOCTYPE html> <html> <body> <p><a id="Anchor" type="text/html" href="https://www.examplesite.com">example site</a></p> <p><a id="Anchor2" href="https://www.example.com">example</a></p> <p>Click the buttons to set and get the type attribute.</p> <button onclick="getType1()">GetType</button> <button onclick="setType2()">SetType</button> <p id="Type1"></p> <script> function getType1() { var x = document.getElementById("Anchor").type; document.getElementById("Type1").innerHTML = x; } function setType2(){ document.getElementById("Type1").innerHTML="Type has been set"; document.getElementById("Anchor2").type="text/html"; } </script> </body> </html></pre><h2>Output</h2><p>This will produce the following output −</p><p><img src="https://www.tutorialspoint.com/assets/questions/media/26306/anchor_type.jpg" class="fr-fic fr-dib" style="width:587px; height:210px;border:1px solid black;" width="587" height="210"></p><p>On clicking GetType button −</p><p><img src="https://www.tutorialspoint.com/assets/questions/media/26306/anchor_type1.jpg" class="fr-fic fr-dib" style="width:589px; height:210px;border:1px solid black;" width="589" height="210"></p><p>On clicking SetType button −</p><p><img src="https://www.tutorialspoint.com/assets/questions/media/26306/anchor_type2.jpg" class="fr-fic fr-dib" style="width:589px; height:210px;border:1px solid black;" width="589" height="210"></p><p>In the above example −</p><p>We have taken two links with id Anchor and Anchor2 respectively. Anchor1 has MIME type text/html associated with it while Anchor2 doesn’t have any MIME type associated with it.</p><pre class="result notranslate"><p><a id="Anchor" type="text/html" href="https://www.examplesite.com">example site</a></p> <p><a id="Anchor2" href="https://www.example.com">example</a></p></pre><p>We then have two buttons GetType and SetType to execute functions getType1() and getType2() respectively.</p><pre class="result notranslate"><button onclick="getType1()">GetType</button> <button onclick="setType2()">SetType</button></pre><p>The getType1() function returns the type of the anchor tag with id “Anchor” associated with it. The setType2() function sets the type of the anchor tag with id “Anchor2” to text/html.</p><pre class="result notranslate">function getType1() { var x = document.getElementById("Anchor").type; document.getElementById("Type1").innerHTML = x; } function setType2(){ document.getElementById("Type1").innerHTML="Type has been set"; document.getElementById("Anchor2").type="text/html"; }</pre>
- Related Questions & Answers
- HTML DOM Anchor rel Property
- HTML DOM Anchor search Property
- HTML DOM Anchor target Property
- HTML DOM Anchor text Property
- HTML DOM Anchor username Property
- HTML DOM Anchor protocol Property
- HTML DOM Anchor password Property
- HTML DOM Anchor pathname Property
- HTML DOM Anchor href Property
- HTML DOM Anchor origin Property
- HTML DOM Anchor port Property
- HTML DOM Anchor hreflang Property
- HTML DOM Anchor download Property
- HTML DOM Anchor hash Property
- HTML DOM Anchor hostname Property
Advertisements