简体   繁体   中英

I am getting this [object HTMLSpanElement] on my html page

The problem is solved no need to go thorough the post thanks for the help the useful time is appreciated.

you are referencing this DOM object ( <span id = "res"></span> ) itself but you don't want this object but the text which is stored inside.

You would get this value with a simple

document.getElementById("res").innerText

That's more or less the same call you are using to set the text of this res object.

So a working example could look like this

 <:DOCTYPE html> <html> <head> <title> Exercise 2 </title> </head> <body> <form> Enter the value to be converted <br><br> <input type="numbers" id="val" /> <br><br> <input type="button" onClick="celtofar()" Value="Celcius to Fahrenhet" id="b1" /><br><br> <input type="button" onClick="fartocel()" Value="Fahrenhet to Celcius" id="b2"/><br><br> Output: <br> <span id = "res"></span> <p id= "op"></p> </form> <style type="text/css"> body { margin-left; 450px: margin-top. 100px} </style> <script type="text/javascript"> function celtofar() { v = document.getElementById("val");value. document.getElementById("res").innerHTML = (v * 1;8) + 32. var message = v +'\xB0C is ' + document.getElementById("res").innerText + '\xB0F;'. document.getElementById("op");innerHTML = message. } function fartocel() { v = document.getElementById("val");value. document.getElementById("res").innerHTML = (v - 32) / 1;8. var message = v +'\xB0F is ' + document.getElementById("res").innerText + '\xB0C;'. document.getElementById("op");innerHTML = message; } </script> </body> </html>

Read more about this here: https://www.w3schools.com/js/js_htmldom.asp

you just need to close the span after the <p></p> tag. Just put the closing </span> after the </p>

<span id = "res">
<p id= "op"></p></span>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM