InnerHTML
1. Find element--document.getelementbyid ("Intro")
2. Results of output Lookup:
(1) var A=document.getelementbyid ("Intro");
document.write (a.innerhtml);
(2) <div id= "Me" ><b> try it </b></div>
var B=document.getelementbyid ("Me");
document.write (b.innerhtml); Write output try it.
Alert ( b.innerhtml)//alert output is <b> try it </b> code + text
Alert (b.innertext)//Output Text only-try it
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">//find elements in HTML by IDvarA=document.getelementbyid ("Intro");d ocument.write (a.innerhtml);varB=document.getelementbyid ("Me");d ocument.write (b.innerhtml);//write output try it.Alert (b.innerhtml)//alert output is <b> try it </b> code + textAlert (B.innertext)//output Text Onlyb.innerhtml=" ";//assign an empty stringB.innerhtml= "<font color=red> I changed </font>";//re-set content//can be written directly/*var B=document.getelementbyid ("Me");d ocument.write (b.innerhtml= "I Changed")*/</script>
The result is:
Example: Using the ID of the P tag to get the content and modify it to the new content
<! DOCTYPE html> document.getElementById ("P1"). Innerhtml= "New text!"; </script><p> the above paragraph was modified by a JavaScript script. </p></body>
Results:
New text!
The above paragraph was modified by a JavaScript script.
Another example:
The same way, just a different notation.
<! DOCTYPE html>var element= document.getElementById ("header"); element.innerhtml= "New header"; </script><p> "Old Header" has been modified to "New header". </p></body>
New Header"Old Header" has been modified to "New header".
To give another, change the picture:
<! DOCTYPE html> document.getElementById ("image"). src= "/i/shanghai_lupu_bridge.jpg"; </script><p> Original picture is Tulip (eg_tulip.jpg), but has been modified to Lupu Bridge (shanghai_lupu_bridge.jpg). </p></body>
The original picture is Tulip (eg_tulip.jpg), but has been modified to Lupu Bridge (shanghai_lupu_bridge.jpg).
Javascrip--dom action (Find HTML element/modify Element)