Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Last active April 10, 2018 00:37
Show Gist options
  • Save jordanhudgens/dcbb4f054c281628e3b280d3fb51616d to your computer and use it in GitHub Desktop.
Save jordanhudgens/dcbb4f054c281628e3b280d3fb51616d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title></title>
</head>
<body>
<div class="widget">
<input type="text" id="chat-input">
<button id="show-profile" onclick="sendMessage()">Show Social</button>
</div>
</body>
<script>
function sendMessage() {
const newDiv = document.createElement("div");
newDiv.classList.add('chatMsg');
let chatInput = document.querySelector('#chat-input').value;
const newContent = document.createTextNode(chatInput);
newDiv.appendChild(newContent);
const widget = document.querySelector(".widget");
let chatWrapper = document.querySelector("show-profile");
document.querySelector('#chat-input').value = '';
if (document.querySelectorAll('.chatMsg').length > 0) {
chatWrapper = document.querySelectorAll('.chatMsg')[0];
}
widget.insertBefore(newDiv, chatWrapper);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment