Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mySolution() {
- let textInputContainer = document.getElementById('inputSection').children[0];
- let userContainer = document.getElementById('inputSection').children[1].children;
- let userImgContainer = userContainer[0];
- let userNameContainer = userContainer[1];
- let sendBtn = userContainer[2];
- let pendingContainer = document.getElementById('pendingQuestions'); //add should with appendChild
- function addPendingInfo() {
- let name = '';
- if (userNameContainer.value === '') {
- name = 'Anonymous';
- } else {
- name = userNameContainer.value;
- }
- let div = document.createElement('div');
- div.className = 'pendingQuestion';
- let pendingHtml = `<img src="${userImgContainer.attributes.src.value}" width="32" height="32" /><span>${name}</span><p>${textInputContainer.value}</p><div class="actions"><button class="archive">Archive</button><button class="open">Open</button></div>`;
- div.innerHTML = pendingHtml
- pendingContainer.appendChild(div);
- userNameContainer.value = "";
- textInputContainer.value = "";
- Array.from(document.getElementsByClassName('actions'))
- .forEach(el => el
- .addEventListener('click', function(event) {
- if (event.target.innerHTML==='Archive') {
- archieve(this);
- } else {
- open(this);
- }
- }));
- }
- function archieve(event) {
- console.log('archive');
- }
- function open(event) {
- console.log('open');
- }
- sendBtn.addEventListener('click', addPendingInfo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement