Jaela Jaela - 4 months ago 7
CSS Question

how to have a css in javascript when onsubmit trigger in another window?

function welcome() {
var Name = document.getElementById("name").value;

var form = "<h1>" + "HI " + Name + " READY YOUR REFLEXES!" + "</h1>";
document.write(form);
return false;
}


how to have a css in javascript when onsubmit trigger in another window. THANK YOU!

Answer

Being quick : A way for adding a style to your inserted title is to add a class to it :

var form = "<h1 class='myclass'>HI  " + Name  + " READY YOUR REFLEXES!" + "</h1>";

Then create a css rule:

.myclass{color:red;}

     
    function welcome(){
      var Name = document.getElementById("name").value; 
      
      //var form = "<h1>" + "HI  " + Name  + " READY YOUR REFLEXES!" + "</h1>";
      var form = "<h1 class='myclass'>HI  " + Name  + " READY YOUR REFLEXES!" + "</h1>";
      document.getElementById("result").innerHTML=form;
      return false;    
    }
      .myclass{color:red;}
    <button type="button" onclick="welcome()" value="Welcome">Welcome</button>
      <input id="name" type="text" value="">
<div id="result"></div>

Comments