/    Sign up×
Community /Pin to ProfileBookmark

document.write in <div>?

just wondering… is it possible to write something specificle yo a <div>? and whats the coding for it?

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 10.2005 — Hi!

That depends on when you want to write it and again depending on that, what you want to write. Can you please point out whether you want to write to the div while the page is loading and - if this is not the case - what you want to write?

Cheers - Pit
Copy linkTweet thisAlerts:
@FangFeb 10.2005 — If the div just contains text:

document.getElementById('elmID').firstChild.data="new text";

or if it contains elements (simple version):

document.getElementById('elmID').innerHTML="<strong>new text</strong>";
Copy linkTweet thisAlerts:
@age13kidauthorFeb 10.2005 — well heres the thing i want to wright it as soon as the page loads ... can it also write links? and variablse that i made?
Copy linkTweet thisAlerts:
@PittimannFeb 10.2005 — Hi!

Like this?[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>
Some hardcoded content...<br><br>
<script language="JavaScript" type="text/javascript">
<!--
var link1='<a href="blah.htm" title="&nbsp;first link&nbsp;">blah</a>';
document.write(link1);
document.close();
//-->
</script>
<br><br>Another hardcoded content
</body>
</html>[/code]
Cheers - Pit
Copy linkTweet thisAlerts:
@age13kidauthorFeb 10.2005 — actually i want it to work like this: the script is at the very top of the page and it writes to a <div> tag with the variable and writes the link.
Copy linkTweet thisAlerts:
@PittimannFeb 10.2005 — Are you sure, you don't want to write something somewhere dynamically after page load? I guess, your direction should be closer to what Fang posted than to my suggestion.

Cheers - Pit
Copy linkTweet thisAlerts:
@FangFeb 11.2005 — Show us the code of what you would like to do.
Copy linkTweet thisAlerts:
@age13kidauthorFeb 11.2005 — <i>
</i>&lt;script type="text/javascript"&gt;
firstpart = "travist120";
secondpart = "gmail.com";
textshown = "Email Me2";
var email = mailpart1+"@"+mailpart2;

document.write("&lt;a href="mailto:" +email+ ""&gt;" +textshown+ "&lt;/a&gt;this is javascript&lt;br&gt;&lt;br&gt;");
&lt;/script&gt;
Copy linkTweet thisAlerts:
@PittimannFeb 11.2005 — Hi!

Simply place the script between an opening and a closing div tag:[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>
<div>
<script type="text/javascript">
firstpart = "travist120";
secondpart = "gmail.com";
textshown = "Email Me2";
var email = firstpart+"@"+secondpart;
document.write("<a href="mailto:" +email+ "">" +textshown+ "</a>this is javascript<br><br>");
</script>
</div>
</body>
</html>[/code]
Cheers - Pit
×

Success!

Help @age13kid 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 5.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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