JavaScript से फॉन्ट फैमिली बदलना
फॉन्ट फैमिली सेट करने के लिए, JavaScript में fontFamily प्रॉपर्टी का उपयोग करें।
उदाहरण
<!DOCTYPE html>
<html>
<body>
<h1>शीर्षक 1</h1>
<p id="myID">
यह डेमो टेक्स्ट है। यह डेमो टेक्स्ट है। यह डेमो टेक्स्ट है।
</p>
<button type="button" onclick="display()">फॉन्ट फैमिली सेट करें</button>
<script>
function display() {
document.getElementById("myID").style.fontFamily = "verdana, sans-serif";
}
</script>
</body>
</html>
व्याख्या
element.style.fontFamilyCSSfont-familyप्रॉपर्टी को सेट करता है।- मान एक कॉमा-सूची हो सकती है:
"Arial, Helvetica, sans-serif"। - ब्राउज़र सूची में पहले उपलब्ध फॉन्ट का उपयोग करता है।
अन्य फॉन्ट प्रॉपर्टीज
| प्रॉपर्टी | CSS समतुल्य | उदाहरण |
|---|---|---|
fontSize | font-size | "16px", "1.2rem" |
fontWeight | font-weight | "bold", "700" |
fontStyle | font-style | "italic" |
fontVariant | font-variant | "small-caps" |
lineHeight | line-height | "1.5" |