অ্যাঙ্কর ট্যাগের সাথে যুক্ত HTML DOM type প্রোপার্টি লিংকের type অ্যাট্রিবিউটের মান সেট বা পাওয়ার জন্য ব্যবহৃত হয়। এই অ্যাট্রিবিউট HTML 5-এ পরিচয় করানো হয়েছিল। এই অ্যাট্রিবিউট শুধু সাজেশনারের জন্য এবং বাধ্যতামূলক নয়। এতে একক MIME (Multipurpose Internet Mail Extensions) ভ্যালু টাইপ থাকে।
সিনট্যাক্স
নিচে সিনট্যাক্স দেওয়া হলো:
type প্রোপার্টি রিটার্ন করা:
anchorObject.type
type প্রোপার্টি সেট করা:
anchorObject.type = MIME-type
উদাহরণ
Anchor text প্রোপার্টির জন্য একটি উদাহরণ দেখি:
<!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>
আউটপুট
এটি নিচের আউটপুট দেবে:

GetType বাটনে ক্লিক করলে:

SetType বাটনে ক্লিক করলে:

উপরের উদাহরণে:
আমরা id Anchor এবং Anchor2 সহ দুটি লিংক নিয়েছি। Anchor1-এর সাথে MIME type text/html যুক্ত আছে যখন Anchor2-এর সাথে কোনো MIME type যুক্ত নেই।
<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>
আমরা তারপর GetType এবং SetType নামে দুটি বাটন তৈরি করেছি যারা যথাক্রমে getType1() এবং getType2() ফাংশন এক্সিকিউট করবে।
<button onclick="getType1()">GetType</button> <button onclick="setType2()">SetType</button>
getType1() ফাংশন id "Anchor" সহ অ্যাঙ্কর ট্যাগের type রিটার্ন করে। setType2() ফাংশন id "Anchor2" সহ অ্যাঙ্কর ট্যাগের type text/html-এ সেট করে।
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"; }