Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
function toggle() { console.log("hello") let articleSection=Array.from(document.getElementsByTagName("section"))[0]; articleSection.innerHTML=""; //fetch all articles var requestOptions = { method: 'GET', redirect: 'follow' }; fetch("http://localhost:3030/jsonstore/advanced/articles/list", requestOptions) .then(response => response.json()) .then(result => populate(result)) .catch(error => console.log('error', error)); function populate(result){ console.log(result) result.forEach(a => { let divAcordeon=document.createElement("div"); divAcordeon.className="accordion" let headDiv=document.createElement("div"); headDiv.className="head"; headDiv.textContent=a.title; let buttonSpan=document.createElement("span"); buttonSpan.className="button"; buttonSpan.textContent="More"; headDiv.appendChild(buttonSpan); let extraDiv=document.createElement("div"); extraDiv.className="extra"; let contentP=document.createElement("p"); contentP.textContent="defaultContent"; buttonSpan.addEventListener("click", ()=>(populateParagraph(buttonSpan,a._id,contentP,extraDiv))); divAcordeon.appendChild(headDiv); extraDiv.appendChild(contentP); divAcordeon.appendChild(extraDiv); articleSection.appendChild(divAcordeon); }); } function populateParagraph(button,id,paragraph,extraDiv){ if (button.textContent=="More"){ fetch(`http://localhost:3030/jsonstore/advanced/articles/details/${id}`, requestOptions) .then(response => response.json()) .then(result => { paragraph.textContent=result.content; extraDiv.style.display="block"; button.textContent="Less"; }) .catch(error => console.log('error', error)); } else { extraDiv.style.display="none"; button.textContent="More"; } } } toggle()
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)