EDIT: Edit 2 should answer to the question
<a id="demo" class="button cta-button" onclick="copyToClipboard(document.getElementById('demo').innerHTML)">
Server Ip Here
</a>
Everything between "
is rendered as text.
Example:
var text="value";
console.log(text); //Will render "value"
console.log("text"); //Will render "text"
copyToClipboard(document.getElementById('demo').innerHTML)
is then executed with arg document.getElementById('demo').innerHTML
which is a string here.
Case 1
Your <a>
tags displays the value of your IP server
onclick="copyToClipboard("+document.getElementById('demo').innerHTML+")"
Case 2
Your <a>
tags hides the IP of the server
var ip = "ip address"; //In your javascript file
onclick="copyToClipboard("+ip+")"
Warning: Your ip value must be declared in the top of your HTML file in <script>
tag or a file before the html is rendered in your body, else ip
value is null and your <a>
tag will have a wrong value onclick="copyToClipboard()"
EDIT 2
Considering the script part okay
<a id="demo" class="button cta-button" onclick="copyToClipboard('192.168.1.1')">
Click here to copy ip
</a>
document.getElementById('demo').innerHTML
gives you everything inside your tags <a id="demo">
tags, so in your example it was “Server Ip Here”. However that is not what you were expecting, so you can change it by the value of your IP server.
This works:
<script>
function copyToClipboard(text) {
window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
</script>
<a id="demo" class="button cta-button" onclick="copyToClipboard('192.168.1.1')">
Click here to copy ip
</a>
About <a>
tags, give a try to the Try it yourself to understand how do they work
http://www.w3schools.com/tags/tag_a.asp