<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title></title> <style>Div{width:500px;Height:20px;Border:2px solid Red; } </style></Head><Body><inputtype= "button"value= "button"ID= "BT"/><DivID= "DV">Wow, that's great.</Div><Scriptsrc= "Common.js"></Script><Script> //set any text content in the middle of a label functionSetinnertext (element, text) {//determine if the browser supports this property if (typeofelement.textcontent== "undefined") {Element.innertext=text; } Else{element.textcontent=text; } } //get text content in the middle of any label functionGetinnertext (Element) {if (typeofelement.textcontent== "undefined") { returnElement.innertext; } Else { returnelement.textcontent; } } //Test //my$ ("BT"). onclick = function () { //alert (Getinnertext (my$ ("DV"))); // };my$ ("BT"). onclick= function() {Setinnertext (my$ ("DV"), "It 's really good."); };</Script></Body></HTML>
JavaScript DOM Action case Encapsulation innertext with textcontent function (browser compatible)