JavaScript Tutorial/DOM Node/outerText
Версия от 18:52, 25 мая 2010; (обсуждение)
Get outerText value for a tag (Firefox does not support the outerText.)
<html>
<head>
<title>OuterText Example</title>
<script type="text/javascript">
function useOuterText() {
var oDiv = document.getElementById("div1");
alert(oDiv.outerText);
oDiv.outerText = "new value";
alert(document.getElementById("div1"));
}
</script>
</head>
<body>
<div id="div1" >This is my original text</div>
<input type="button" value="Use OuterText" onclick="useOuterText()" />
</body>
</html>
Set outer Text (Firefox does not support the innerText property.)
<html>
<head>
<title>OuterText Example</title>
<script type="text/javascript">
function useOuterText() {
var oDiv = document.getElementById("div1");
oDiv.outerText = "This is some new text not inside a DIV.";
}
</script>
</head>
<body>
<div id="div1">This is my original DIV</div>
<input type="button" value="Use OuterText" onclick="useOuterText()" />
</body>
</html>