How to assign a variable value to an HTML input created in Javascript / How to style HTML elements in Javascript


Here's the code I am currently using.

function firstChildAge() { 
                        var header = document.createElement('H1'); 
                        var body = document.getElementsByTagName('BODY'); 
                        var textnode = document.createTextNode("WHAT IS THE AGE OF THE FIRST CHILD?"); 
                        var inputChildOne = document.createElement("Input");

a) How would I assign a variable value to the response created by the user to the Input?

b) How can I style elements inside Javascript? For example, how can I make the text "WHAT IS THE AGE OF THE FIRST CHILD?" red, or change the font size?

Thank you!!!


will return the content of the html input.

as for styling, you can either do something like = "color:red; font-size: 20px";
or if you only want to apply one thing = "red";
(Although I'd recommend the first method)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.