This page has been robot translated, sorry for typos if any. Original content here.

Sharing innerHTML and onMouseOver

This note is the simplest example of using the methods and properties of innerHTML and onMouseOver to dynamically change the text on a page. So the simplest example of changing the text when you hover a link to the desired link (and in general any other container)
 <html> <script type = "text / javascript"> <! - function change_desc () {//desc.innerHTML=" Changed the contents of the paragraph with id = 'desc' ";  not a universal version of document.getElementById ("desc"). innerHTML = "Changed the contents of the paragraph with id = 'desc'";  } -> </ script> <p id = "desc"> Paragraph with variable 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 = "Accordingly, text1";
 text2 = "Accordingly, text2";
 function change_desc (v) {
 //desc.innerHTML=" Modified paragraph content with id = 'desc' ";  not a universal option
 document.getElementById ("desc"). innerHTML = v;
 }
 ->
 </ script>
 <p id = "desc"> Paragraph with variable text </ p>
 <! - we start our microfunction with parameters in the form of a constant name with texts ->
 <a href="#" onMouseOver="change_desc(text1)" onMouseOut="change_desc(default_text)"> Change text to 1st </a>
 <a href="#" onMouseOver="change_desc(text2)" onMouseOut="change_desc(default_text)"> Change the text to the second </a>

 </ html>

Note:
If, when testing JavaScript, FireBug displays the message "the name of a variable, constant or function 'is not defined", you need to check your code for correctness. For example, if there are unscreened quotes (") in the contents of a constant, and a semicolon (;) character may be missing before the function is declared.