HTML in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

HTML in JavaScript

Hello World, how can I center a document.write() in javascript ?

12th Apr 2018, 4:59 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
16 Answers
+ 7
document.write("<p style=text-align:center;>text</p>")
12th Apr 2018, 5:43 PM
Ranjan Bagri
Ranjan Bagri - avatar
+ 5
Dont you forget to write window.onload () before changing attributes or writing text into document?
12th Apr 2018, 7:15 PM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 5
// JS window.onload = function() { // all your js code here }
12th Apr 2018, 7:21 PM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 3
No, it will be called automatically when your html page will be full loaded
12th Apr 2018, 7:23 PM
Rull Deef 🐺
Rull Deef 🐺 - avatar
+ 1
Samuele visto che sono anche io italiano ti scrivo un questa lingua... Quello ke voglio farti capure che quando tu scrivi una pagina html devi seguire certe regole... alcune sono obbligatorie (come il formato degli attributi) altri sn facoltativi: <p align="center">..... <p align=center>.... <p align:center>... I primi due casi mostrano i corretti usi per dichiarare degli attributi (sebbene sia congliata la prima versione con le virgolette non è obbligatorio)... La terza invece è fa in modo che il browser non accetti l attributo align perchè non ne riconosce il formato (è obbligatorio usare il segno =)... Queste regole sono definite dallo standard HTML (che in maniera molto semplice e approssimativa è un insieme di regole a cui devono aderire tutti gli implementatori di browser e gli sviluppatori di pagine Web)
12th Apr 2018, 6:48 PM
KrOW
KrOW - avatar
+ 1
12th Apr 2018, 8:14 PM
KrOW
KrOW - avatar
+ 1
thanks
12th Apr 2018, 8:15 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
0
and why if i code document.write("<p style:vertical-align: center;> Text </p> it doesnt work?
12th Apr 2018, 5:49 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
0
Because HTML standards tell that attributes must be defined in attrName="attrValue" format and browsers must use it
12th Apr 2018, 6:36 PM
KrOW
KrOW - avatar
0
can you make an example, i dont understand so well
12th Apr 2018, 6:37 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
0
ah perfetto quindi se io scrivessi: <p style="vertical-align:center">Text</p> è corretto ?
12th Apr 2018, 7:03 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
0
si... Bada bene ke quel: fa parte della sintassi utilizzata dalle regole CSS (per gli stili)
12th Apr 2018, 7:09 PM
KrOW
KrOW - avatar
0
sisi certo, è un po' di tempo che non riprendevo html e css. ora sto iniziando con js
12th Apr 2018, 7:10 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
0
where ?
12th Apr 2018, 7:18 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
0
and then recall the function ?
12th Apr 2018, 7:22 PM
Samuele Sacchetti
Samuele Sacchetti - avatar
0
i will try
12th Apr 2018, 7:28 PM
Samuele Sacchetti
Samuele Sacchetti - avatar