- 1

Why <br /> tag doesn't perform along with alert() function?

For code var x; { for(x=2;x<=1024;x*=2) alert(x+"<br />") ; }

13th Jan 2018, 7:19 AM
anurag singh
anurag singh - avatar
10 odpowiedzi
+ 2
It doesn't bring any changes, until you append another string to it instead: var y = 42; alert(x+"\n"+y); ... or put more than once to see that it introduces new empty lines (even only once, but that's not easily visible): alert(x+"\n\n\n");
13th Jan 2018, 9:50 AM
visph
visph - avatar
+ 2
// something like that? var x, s = ""; for(x=2;x<=1024;x*=2) { s += x+"\n"; } alert(s);
13th Jan 2018, 10:20 AM
visph
visph - avatar
+ 1
try \n instead
13th Jan 2018, 7:36 AM
Jeremy
Jeremy - avatar
+ 1
Because alert() window content text is not part of the html document, but part of the operating system, called through the browser ^^ As @Jeremy advices, use alert(x+"\n") instead ;)
13th Jan 2018, 9:11 AM
visph
visph - avatar
+ 1
Absolutly not: document.write() is a JS function to access to document API and write inside the html document ;P
13th Jan 2018, 9:41 AM
visph
visph - avatar
0
<br /> tag still works with document. write() function which is also not part of HTML document but JavaScript. document.write(x+"<br />") @visph
13th Jan 2018, 9:39 AM
anurag singh
anurag singh - avatar
0
because only single inverted comaa is used for tags
13th Jan 2018, 4:09 PM
Ayush
Ayush - avatar
- 1
(x+"\n") and (x) perform similarly in above coding. \n doesn't bring any changes. @jeremy & @visph
13th Jan 2018, 9:45 AM
anurag singh
anurag singh - avatar
- 1
https://code.sololearn.com/WZIZsdCNF99C/?ref=app In this code we get all the output in single tabular form instead on using alert() function (as mentioned above in original question). we get each individual output in separate popup. Can't we get all output in single popup. @vipsh ; @jeremy
13th Jan 2018, 10:18 AM
anurag singh
anurag singh - avatar
- 1
Have u read all the discussion (questions & answers) on this post. Sure Single inverted comma matters here @ayush
13th Jan 2018, 4:30 PM
anurag singh
anurag singh - avatar