1

How can I use html tag in this javascript?

First of all, why <br> doesn't work in prompt. Secondly, why can't I use tags for this code (poundOne.pound) to make the font larger by using css or html code such as <h1>, <h2>, <h3>... or <div style="......">?

<html>
<head>
<script type="text/javascript">


function poundToKgConvertor( pound ){
    this.pound = pound;
    this.convertorDon = convertor;
}
function convertor(){
    var convert = this.pound * 0.453592;
    return convert;
}

var poundOne = new poundToKgConvertor(prompt ("Convert Pound to Kilogram!<br> Please insert your    number of pound!"));
</script>

</head>

<body>

<script type="text/javascript">


document.write(poundOne.pound +  " Pound = " + poundOne.convertorDon() + " <b>Kilogram</b>");

</script>

</body>
</html>
David Thomas
  • 249,100
  • 51
  • 377
  • 410
Tohid
  • 13
  • 2

1 Answers1

2

You can't use HTML in prompt/alert dialogs. However you can use new line characters:

prompt ("Convert Pound to Kilogram!\n Please insert your number of pound!");
dfsq
  • 191,768
  • 25
  • 236
  • 258
  • Thank you! but anyone knows about my second question? – Tohid Oct 05 '14 at 18:21
  • Sorry, what is the seconds question? Why you can't use HTML there? The answer: because prompt/alert is not a part of HTML structure, it's not DOM. – dfsq Oct 05 '14 at 18:23
  • yes i know is not part of HTML. Second question: why can't I use tags for this code (poundOne.pound) to make the font larger by using css or html code such as

    ,

    ,

    ... or
    ?

    – Tohid Oct 05 '14 at 18:28
  • not sure I get it: http://plnkr.co/edit/usI0GEAs0uK4Hzz6oYhv?p=preview – dfsq Oct 05 '14 at 18:46