The most basic style is the font face and size. This shows that the Normal style controls paragraphs, does not inherit from another style, uses Calibri 11, has 1.08 line spacing, has 8 pt spacing after the end of the paragraph, uses widow/orphan control, and is shown in the styles gallery.Įvery character in a word document has some style associated with it. For example, to view the Normal style, in the Home ribbon, R-click the Normal style and select Modify. Each style has a name that is associated with all of the controls for the style. A button, “Set Font Family” is associated with a click event that executes the “setFontFamily()” function, which sets the font family of an element.Styles in Word control nearly all aspects of a document’s appearance. We have used an input field to take the user’s input for the list of font families. In the below example, we have used the tProperty method to set the font family for text with JavaScript. Priority − The priority of the property value (Optional). Property_name − The name of the property to be set. In the above syntax, we access the element object of an HTML element that has an id of ‘id’ using the document.getElementById() method and then use the tProperty method. Syntax const element = document.getElementById('id')Į(property_name, value, priority) In the property name parameter of the tProperty method, it should be ‘font-family’, and the value and priority will be as per the user. The tProperty method is a part of the element object, so to use this method, we need to access the element object using the document.getElementById() method and then we can use this method. In JavaScript, any new or existing property of an HTML element can be set using the tProperty method. fontFamily property with JavaScript Set Font Family This text will use Arial font family This text will use cursive font family This text will use Helvetica, sans -serif font family This text will use Georgia, serif font family // 'Set Font Family' button click event handler function function setFontFamily ( ) We have used a button “Set Font Family” click event to execute the “setFontFamily()” function that sets the font-family property of multiple elements.īackground -color : aliceblue } Set the font family for text using style. In the below example, we have used the style.fontFamily property to set the font family for text with JavaScript. Initial − The font-family property is set to default. Inherit − The font-family property is inherited by its parent element’s property. Generic_family − The name of one or multiple generic families. Parametersįamily_name − The name of one or multiple font families. Using the document.getElementById() method we are accessing that element object and set the style.fontFamily property. In the above syntax, the ‘id’ is the id of an element. Syntax const element = document.getElementById('id')Į = family_name | generic_family | inherit | initial The element object contains this property, so first, the document.getElementById() method is used to access the element object, and then we use the style.fontFamily property to set the font family for text with JavaScript. The browser will set the first value from the list that it recognizes. The style.fontFamily property sets a list of font family names and/or generic family names for the text. To set the font-family for text with JavaScript, we have multiple ways, and in this tutorial, we will discuss two of them − The font-family is a CSS property that specifies a prioritized list containing one or more font family names and generic family names for the text of an HTML element. In this tutorial, we will learn how to set the font family for text with JavaScript.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |