EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

innerText property

Sets or retrieves the text between the start and end tags of the object.

Syntax

JavaScript

text = object.innerText

 

Property values

Type: String

the text between the start and end tags.

Remarks

The innerText property is valid for block elements only. By definition, elements that do not have both an opening and closing tag cannot have an innerText property.

The innerText property is read-only on the html, table, tBody, tFoot, tHead, and tr objects.

When the innerText property is set, the given string completely replaces the existing content of the object.

You can set this property only after the onload event fires on the window. When dynamically creating a tag using TextRange, innerHTML, or outerHTML, use Microsoft JScript to create new events to handle the newly formed tags. Microsoft Visual Basic Scripting Edition (VBScript) is not supported.

You can change the value of the title element using the document.title property.

To change the contents of the table, tFoot, tHead, and tr elements, use the table object model. For example, use the rowIndex property or the rows collection to retrieve a reference to a specific table row. You can add or delete rows using the insertRow and deleteRow methods. To retrieve a reference to a specific cell, use the cellIndex property or the cells collection. You can add or delete rows using the insertCell and deleteCell methods. To change the content of a particular cell, use the innerHTML property.

Security Warning:   The innerText property can be used to safely add dynamic text to a webpage if the target element type is not a script element. With the exception of the script element, innerText does not execute script when inserting text into the Document Object Model (DOM) of a webpage.

Examples

This example uses the innerText property to replace an object's contents. The object surrounding the text is not replaced.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/innerText.htm


<p id=oPara>Here's the text that will change.</p>
:
<button onclick="oPara.innerText='WOW! It changed!'">Change text</button>
<button onclick="oPara.innerText='And back again'">Reset</button>

See also

a
abbr
acronym
address
applet
area
article
aside
b
bdo
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
custom
dd
del
dfn
dir
div
dl
dt
em
embed
fieldSet
figcaption
figure
font
footer
form
frame
frameSet
head
header
hgroup
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=email
input type=file
input type=hidden
input type=image
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
ins
isIndex
kbd
label
legend
li
listing
map
mark
marquee
menu
nav
nextID
noBR
object
ol
optGroup
option
p
plainText
pre
q
rt
ruby
s
samp
section
select
small
span
strike
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
tt
u
ul
var
xmp
insertAdjacentText

 

 

Afficher:
© 2014 Microsoft