Html tag inside javascript

I am trying to use some html tag inside Javascript. But the Html tag does not work. How can I use the html tag inside javascript. I wanted to use the h1 tag inside Javascript, but it didn't work :(

<script type="text/javascript"> if(document.getElementById('number1').checked) { <h1>Hello member</h1>} </script> 
+6
source share
7 answers

You will either have to document.write it, or use the document object model:

Example usage document.write

 <script type="text/javascript"> if(document.getElementById('number1').checked) { document.write("<h1>Hello member</h1>"); } </script> 

DOM example

 <script type="text/javascript"> window.onload = function() { if(document.getElementById('number1').checked) { var h1 = document.createElement("h1"); h1.appendChild(document.createTextNode("Hello member")); document.getElementById("XXX").appendChild(h1); } } </script> 
+5
source

This is what I used for my countdown clock:

 </SCRIPT> <center class="auto-style19" style="height: 31px"> <Font face="blacksmith" size="large"><strong> <SCRIPT LANGUAGE="JavaScript"> var header = "You have <I><font color=red>" + getDaysUntilICD10() + "</font></I>&nbsp; " header += "days until ICD-10 starts!" document.write(header) </SCRIPT> 

The HTML inside my script worked, although I could not explain why.

+1
source

JavaScript is a scripting language, not a type of language. Basically this is to do the process in the background, and it needs document.write display things in the browser. Also, if your document.write exceeds one line, be sure to put a + concatenation at the end of each line.

Example

 <script type="text/javascript"> if(document.getElementById('number1').checked) { document.write("<h1>Hello" + "member</h1>"); } </script> 
0
source
 <div id="demo"></div> <input type="submit" name="submit" id="submit" value="Submit" onClick="return empty()"> <script type="text/javascript"> function empty() { var x; x = document.getElementById("feedbackpost").value; if (x == "") { var demo = document.getElementById("demo"); demo.innerHTML =document.write='<h1>Hello member</h1>'; return false; }; } </script> 
0
source
 <html> <body> <input type="checkbox" id="number1" onclick="number1();">Number 1</br> <p id="h1"></p> <script type="text/javascript"> function number1() { if(document.getElementById('number1').checked) { document.getElementById("h1").innerHTML = "<h1>Hello member</h1>"; } } </script> </body> </html> 
0
source

here how to include html variables and tags in document.write also note how you can just add text between quotes

 document.write("<h1>System Paltform: ", navigator.platform, "</h1>"); 
0
source
  <div id="demo></div> <script type="text/javascript"> if(document.getElementById('number1').checked) { var demo = document.getElementById("demo"); demo.innerHtml='<h1>Hello member</h1>'; } else { demo.innerHtml=''; } </script> 
-1
source

Source: https://habr.com/ru/post/895262/


All Articles