SerkanK
SerkanK

Reputation: 39

Why Javascript innerHTML add quote automatically to my string?

I am trying to add some HTML code and text in a div. If I add just a text there isn't any problem. But if I add some text with HTML code, it automatically adds quotes to my text.

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        function test() {
            document.getElementById("viewer1").innerHTML = "text";// this is not add any quote to text
            document.getElementById("viewer2").innerHTML = "text <b>Bold Text</b>"; //this is add quote to text but not add quote to <b>Bold Text</b>

        }
    </script>
</head>
<body>
<div id="viewer1"></div>
<div id="viewer2"></div>
<button onclick="test()">Test it</button>

</body>
</html>

It looks like this

 viewer1 content = text
 viever2 content ="text" <b>Bold Text</b>

I don't want the quotes. How can it be removed?

Take a look at the screenshot below:

enter image description here

Upvotes: 2

Views: 1570

Answers (1)

Vicky Gill
Vicky Gill

Reputation: 734

The quotes will not shown in web page. it's just for chrome console node.

Upvotes: 4

Related Questions