एचटीएमएल डोम लिंक href संपत्ति एक लिंक किए गए दस्तावेज़ का पथ/यूआरएल सेट/रिटर्न करता है। -
सिंटैक्स
निम्नलिखित वाक्य रचना है -
- लौटना href विशेषता मान
linkObject.href
- सेटिंग href एक स्ट्रिंग के लिए
linkObject.href = string
बूलियन मान
यहाँ, "स्ट्रिंग" निम्नलिखित हो सकती है -
| booleanValue वें> <वें शैली ="पाठ-संरेखण:केंद्र; चौड़ाई:81.2925%;">विवरण वें> | |
|---|---|
| path | यह किसी दस्तावेज़ के निरपेक्ष/सापेक्ष पथ को परिभाषित करता है। |
| url | यह लिंक किए जाने वाले दस्तावेज़ के url पते को परिभाषित करता है। |
उदाहरण
आइए लिंक href . के लिए एक उदाहरण देखें संपत्ति -
<!DOCTYPE html>
<html>
<head>
<title>Link href</title>
<link id="extStyle" rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form>
<fieldset>
<legend>Link-href</legend>
<label for="WeekSelect">Sales Target Week:
<input type="week" id="WeekSelect" value="2020-W13" disabled>
</label>
<input type="button" onclick="enableWeekInput()" value="Change Sales Target Week">
<input type="button" onclick="changeStyle()" value="Change Style">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputWeek = document.getElementById("WeekSelect");
var extStyle = document.getElementById("extStyle");
divDisplay.textContent = 'Week Input disabled: '+inputWeek.disabled;
function enableWeekInput() {
inputWeek.disabled = false;
divDisplay.textContent = 'Week Input disabled: '+inputWeek.disabled;
}
function changeStyle(){
extStyle.href = 'anotherStyle.css';
}
</script>
</body>
</html> उपरोक्त उदाहरण में ‘style.css’ शामिल हैं -
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
} उपरोक्त उदाहरण में ‘anotherStyle.css’ शामिल हैं -
form {
width:70%;
margin: 0 auto;
text-align: center;
background-color: rgba(0,0,0,0.7);
color: white;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
‘शैली बदलें’ clicking क्लिक करने से पहले बटन -

‘शैली बदलें’ clicking क्लिक करने के बाद बटन -
