html - How to Center Text in a JavaScript Function? -
i have javascript function displays text based on input in text field. when value entered text field, program check see if value correct. if correct, program displays, "you correct!" , if incorrect, program displays, "try again!"
the text field , button both centered horizontally on page, cannot figure out how center "you correct!" , "try again!"
i feel have tried everything, haven't, considering can't work.
here code javascript function:
<center><p>can remember how many books listed @ bottom of page?</p></center> <center><input id="numb"></center> <center><button type="button" onclick="myfunction()">submit</button></center> <p id="demo"></p> <div class="jsfunction"> <script> function myfunction() { var x, text; // value of input field id="numb" x = document.getelementbyid("numb").value; // if x not number or less 5 or greater 5 if (isnan(x) || x < 5 || x > 5) { text = "try again!"; } else { text = "you correct!"; } document.getelementbyid("demo").innerhtml = text; } </script> </div> here css code function:
.jsfunction { margin-left: auto; margin-right: auto; } this specific css code 1 of many, many attempts have made @ centering text in function.
here link picture show problem having: http://i.stack.imgur.com/hb01j.png
please help!
try setting class on p tag contains text-align: center;
edit
nesting script in div meaningless script tags don't rendered
you can either target #demo in css (for text alignment) or add class align-center contains correct style.
i recommend latter becomes more reusable, whereas can't reuse id on same page
Comments
Post a Comment