Last active
April 10, 2018 00:37
-
-
Save jordanhudgens/dcbb4f054c281628e3b280d3fb51616d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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