Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- const title_input = document.getElementById('task-title')
- const category_input = document.getElementById('task-category')
- const content_input = document.getElementById('task-content')
- const publish_btn = document.getElementById('publish-btn')
- const review_list_ul = document.getElementById('review-list')
- const published_list_ul = document.getElementById('published-list')
- publish_btn.addEventListener("click", publish_task)
- function publish_task(e) {
- e.preventDefault()
- let title = title_input.value
- let category = category_input.value
- let content = content_input.value
- let li_element = document.createElement('li')
- li_element.classList.add('rpost')
- review_list_ul.appendChild(li_element)
- let article_element = document.createElement('article')
- li_element.appendChild(article_element)
- let h4_element = document.createElement('h4')
- h4_element.textContent = `${title}`
- article_element.appendChild(h4_element)
- let category_p_element = document.createElement('p')
- category_p_element.textContent = `Category: ${category}`
- article_element.appendChild(category_p_element)
- let content_p_element = document.createElement('p')
- content_p_element.textContent = `Content: ${content}`
- article_element.appendChild(content_p_element)
- let edit_btn = document.createElement('button')
- edit_btn.textContent = 'Edit'
- edit_btn.classList.add('action-btn')
- edit_btn.classList.add('edit')
- edit_btn.addEventListener("click", edit_task)
- li_element.appendChild(edit_btn)
- let post_btn = document.createElement('button')
- post_btn.textContent = 'Post'
- post_btn.classList.add('action-btn')
- post_btn.classList.add('post')
- post_btn.addEventListener("click", post_task)
- li_element.appendChild(post_btn)
- title_input.value = ''
- category_input.value = ''
- content_input.value = ''
- }
- function edit_task (edit_event) {
- let event_li = edit_event.currentTarget.parentElement
- let li_children = Array.from(event_li.children)
- let current_article = li_children[0]
- let article_children = Array.from(current_article.children)
- title_input.value = article_children[0].textContent
- category_input.value = article_children[1].textContent.split(': ')[1]
- content_input.value = article_children[2].textContent.split(': ')[1]
- event_li.remove()
- }
- function post_task(post_event) {
- let post_li = post_event.currentTarget.parentElement
- post_li.lastChild.remove()
- post_li.lastChild.remove()
- published_list_ul.appendChild(post_li)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement