Sharing innerHTML and onMouseOver
In the note, the simplest example of using methods and properties of innerHTML and onMouseOver for dynamically changing text on a page.
So the simplest example of changing the text when you hover a link to the desired link (and any other container):
<Html> <Script type = "text / javascript"> <! - Function change_desc () { //desc.innerHTML="Change the contents of the paragraph with id = 'desc' "; Not a universal option Document.getElementById ("desc"). InnerHTML = "Changed the contents of the paragraph with id = 'desc'"; } -> </ Script> <P id = "desc"> Paragraph with changing text </ p> <a href="#" onMouseOver="change_desc()"> Change text </a> </ Html>
This example can be slightly simplified, for example, changing the text in a paragraph to different variants and returning it to its original state after removing the mouse pointer from it using predefined string constants:
<Html> <Script type = "text / javascript"> <! - Default_text = "Standard text"; Text1 = "Respectively text1"; Text2 = "Respectively text2"; Function change_desc (v) { //desc.innerHTML="Change the contents of the paragraph with id = 'desc' "; Not a universal option Document.getElementById ("desc"). InnerHTML = v; } -> </ Script> <P id = "desc"> Paragraph with changing text </ p> <! - run our microfunction with parameters as a constant name with text -> <a href="#" onMouseOver="change_desc(text1)" onMouseOut="change_desc(default_text)"> Change the text to the 1st </a> <a href="#" onMouseOver="change_desc(text2)" onMouseOut="change_desc(default_text)"> Change the text to the 2nd </a> </ Html>
Note:
If, during the testing of the work, JavaScript FireBug displays the message "'variable name, constant or function is not defined", it is necessary to check the code for correctness. For example, if there are unshielded quotes (") in the content of the constant, and there may be no semicolon (;) before the function.
Comments
When commenting on, remember that the content and tone of your message can hurt the feelings of real people, show respect and tolerance to your interlocutors even if you do not share their opinion, your behavior in the conditions of freedom of expression and anonymity provided by the Internet, changes Not only virtual, but also the real world. All comments are hidden from the index, spam is controlled.