221k views
5 votes
Write a JavaScript program to modify the text-align, font- size, font-family of heading using getElementByld

User Histelheim
by
7.3k points

1 Answer

4 votes

Final answer:

To modify heading styles in JavaScript, use `getElementById` to select the element and adjust the `text-align`, `font-size`, and `font-family` properties within the element's `style` attribute.

Step-by-step explanation:

To modify the text-align, font-size, and font-family of a heading using getElementById, you would use JavaScript to directly manipulate the style properties of the HTML element. Here's a simple example:


// Assuming there is an HTML element with an id of 'myHeading'
var heading = document.getElementById('myHeading');

// Set the text alignment to center
heading.style.textAlign = 'center';

// Set the font size to 24 pixels
heading.style.fontSize = '24px';

// Set the font family to Arial
heading.style.fontFamily = 'Arial';

This JavaScript code gets the HTML element with the id 'myHeading', then changes its text alignment to center, font size to 24 pixels, and font family to Arial, respectively.

User Overlord Zurg
by
7.4k points