Report this ad Hiding and Showing Content Using JavaScript The color of the text sould change when the button is pressed" Let's put this togther in an example in which we have a button configured to change the color of some text when it is pressed: The buttonPressed() function in turn accesses the element via the id and changes the color style to 'green'. A button is created which calls the buttonPressed() function when clicked. The following example contains some text contained in a tag assigned the id introtext. Having gained access to the element object we can access the color property of the style object for this element and change the color. ![]() Var myElement = document.getElementById("introtext") The first step is to access the element using the getElementById() method of the document object (see the JavaScript Document Object chapter for details of this object): We can very easily change the color of this text from within JavaScript. ![]() Suppose we have the following HTML: This is some introductory text Using JavaScript the style of any element can be changed via the properties of that element's style object. The W3C DOM (Document Object Model) provides a powerful mechanism for dynamically controlling the styles used in a web page.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |