/    Sign up×
Community /Pin to ProfileBookmark

ID with text

Hi,
Newbie question. I have some text that could be in a <TD>, <P> or <DIV> tag and I would like to know how to access it with the ID field.

<P ID=”AdText”>This is the text</P>


var Text = document.getElementById(‘AdText’);

How do I access the actual text?

Text.?

Thanks,
Tim

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 11.2005 — var Text = document.getElementById('AdText').firstChild.data;
Copy linkTweet thisAlerts:
@PittimannFeb 11.2005 — Hi![code=php]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Example</title>
</head>
<body>
<P ID="AdText">This is the text</P>
<a href="#" onclick="alert(document.getElementById('AdText').firstChild.data)">click me</a>
</body>
</html>[/code]
Cheers - Pit

Edit: Fang is too fast! ?
Copy linkTweet thisAlerts:
@tim8wauthorFeb 11.2005 — I would like to assign new text to that field, i.e.

var Text = document.getElementById('AdText').firstChild.data;

Text = "Some New Text"


and have it update the field with the new text...

Tim
Copy linkTweet thisAlerts:
@tim8wauthorFeb 11.2005 — I figured it out.

var Text = document.getElementById('AdText');

Text.firstChild.data = "Some New Text"

Thanks for all your help...

Tim
×

Success!

Help @tim8w spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...