Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do i get html to display on page instead of running? [duplicate]

My problem seems to be the opposite of the problem most other people have. I do not want HTML in the .innerHTML to run. I want it to display on the page as is. (I know there is another problem in my code. I'm working on that)

https://jsfiddle.net/ojfykv17/ or

<div id="code">

</div>

    function genorateCode() {
    		var account = document.getElementById("account");
        var url = document.getElementById("url");
        sendCode();
    }
    function sendCode() {
    document.getElementById('code').innerHTML = '<a href="'+url+'">'+'<div class="button"><img src="https://s15.postimg.org/mfpd2ki8r/icon.png" width="16">@'+account+'</div></a>';
    }
    sendCode();
    .button {
    border-radius: 5px;
    background-color: white;
    border:1;
    border-style: solid;
    position: fixed;
    padding: 5px 10px 5px 10px;
    border-width: 1.2px;
    line-height: 5px; 
    border-color: #a5aab1;
    font-family: 'Lato', sans-serif;
    font-weight:300;
    text-align: center;
    }
<form id="form" onsubmit="return false;">
        <input type="text" id="account" />
        <input type="text" id="url" />
        <input type="submit" onclick="genorateCode();" />
    </form>
    
    <div id="code">
    
    </div>
like image 666
One SNapp Avatar asked Dec 23 '22 23:12

One SNapp


1 Answers

Instead of setting innerHTML, set the innerText of the element.

document.getElementById('code').innerText = '<a href="'+url+ ...
like image 133
Stephen P Avatar answered Dec 31 '22 12:12

Stephen P