জাভাস্ক্রিপ্ট document.links.href প্রদান করেছে href পেতে প্রয়োজনীয় লিঙ্কের বৈশিষ্ট্য। এই পদ্ধতিটি একটি পদ্ধতির মতোই কাজ করে যা একটি অ্যারেতে একটি নির্দিষ্ট উপাদান প্রদর্শন করে। আসুন সংক্ষেপে আলোচনা করি।
উদাহরণ-1
নিম্নলিখিত উদাহরণে, তিনটি লিঙ্ক প্রদান করা হয়েছে৷ document.links.href ব্যবহার করে 3য় লিঙ্কটি আউটপুটে কার্যকর করা হয়। এটি একটি অ্যারের হিসাবে একই অনুসরণ করে। প্রথম লিঙ্কটি 0 তম সূচী নেবে, দ্বিতীয় লিঙ্কটি 1 ম সূচী নেবে ইত্যাদি।
<html>
<body>
<a href="https://www.tutorialspoint.com/javascript/index.htm">Javascript</a><br>
<a href="https://www.tutorialspoint.com/java8/index.htm">Java</a><br>
<a href="https://www.tutorialspoint.com/spring/index.htm">Spring</a>
<p id="links"></p>
<script>
document.getElementById("links").innerHTML =
"The href attribute is: " + document.links[2].href;
</script>
</body>
</html> আউটপুট
Javascript Java Spring The href attribute is: https://www.tutorialspoint.com/spring/index.htm
উদাহরণ-2
নিম্নলিখিত উদাহরণে, দুটি লিঙ্ক প্রদান করা হয়েছে৷ document.links.href ব্যবহার করে প্রথম লিঙ্কটি আউটপুটে কার্যকর করা হয়।
<html>
<body>
<a href="https://www.tutorialspoint.com/javascript/index.htm">Javascript</a><br>
<a href="https://www.tutorialspoint.com/java8/index.htm">Java</a>;
<p id="links"></p>
<script>
document.getElementById("links").innerHTML =
"The href attribute is: " + document.links[0].href;
</script>
</body>
</html> আউটপুট
Javascript Java The href attribute is: https://www.tutorialspoint.com/javascript/index.htm