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

Sharing innerHTML and onMouseOver

The note is a simple 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 from the 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, while testing the work of the 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 a semicolon (;) character may not exist before the function is committed.