/    Sign up×
Community /Pin to ProfileBookmark

doc.write alternative

I need to write several lines of html in any given page, and am hoping to just load a js file instead.

Is there a javascript method to write more than one line of code?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@jhaankreiiMar 11.2007 — Not sure what you need exactly, but another way you could do it, is create a div on the page, and fill it with what you want.

E.G.

on page.html

<div id="newdiv"></div>

Then in your js file

strOut = "This is line one<br />";

strOut += "This is line two<br />";

document.getElementById("newdiv").innerHTML = strOut;

If that is the type of thing you are after, great! If not, please post more details, so others can offer more help.
Copy linkTweet thisAlerts:
@follishauthorMar 11.2007 — i was hoping for more of a

doc.multiwrite(

line1

line2

lin3

);

kind of deal. ive sinced realized this might not be possible from javascript, if it is, great, otherwise its fine. cool, thanks.
Copy linkTweet thisAlerts:
@felgallMar 11.2007 — A web page isn't made up of lines, it is made up of elements. There are a whole lot of Document Object Model commands available for creating elements and attaching them together prior to adding the whole lot into the web page in one go. Whether the HTML for a page appears as one line or a million lines makes no difference whatever as far as the HTML is concerned (although the more blank space the slower the page will load).
Copy linkTweet thisAlerts:
@jhaankreiiMar 11.2007 — Well if you literally wanted to write line aftter line, you could use <pre></pre> tags

I believe they take note of whitespace, tabs, enters etc. Not 100% sure, i don't use them myself. But it's worth looking into to.
×

Success!

Help @follish 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.16,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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