Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to print card by taking value by array in javascript

const apiResult = [{
  title: "title1",
  description: "desc1",
  output: "out1"
}, {
  title: "title2",
  description: "desc2",
  output: "out2"
}, {
  title: "title3",
  description: "desc3",
  output: "out3"
}];


const container = document.getElementById('accordion');

apiResult.forEach((result, idx) => {
  // Create card element
  const card = document.createElement('div');
  card.classList = 'card-body';

  // Construct card content
  const content = `
    <div class="card">
    <div class="card-header" id="heading-${idx}">
      <h5 class="mb-0">
        <button class="btn btn-link" data-toggle="collapse" data-target="#collapse-${idx}" aria-expanded="true" aria-controls="collapse-${idx}">

                </button>
      </h5>
    </div>

    <div id="collapse-${idx}" class="collapse show" aria-labelledby="heading-${idx}" data-parent="#accordion">
      <div class="card-body">

        <h5>${result.title}</h5>
        <p>${result.description}</p>
        <p>${result.output}</p>
        ...
      </div>
    </div>
  </div>
  `;

  // Append newyly created card element to the container
  container.innerHTML += content;
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to combine folder for render in express js 
Javascript :: Assign arrow function to a variable before exporting as module default 
Javascript :: direction of scroll on page 
Javascript :: http://strongerw2ise74v3duebgsvug4mehyhlpa7f6kfwnas7zofs3kov7yd.onion/all 
Javascript :: supabase realtime connection 
Javascript :: react native bottom sheet example 
Javascript :: json.parse() javascript 
Javascript :: disable click extra collapse antd 
Javascript :: switch case block scope 
Javascript :: node_modules edux-sagaesindex.js 
Javascript :: disable a tag javascript void 
Javascript :: javascript promise multi function error 
Javascript :: on second click javascript 
Javascript :: md5 online decrypt 
Javascript :: dynamically define routes separated in different pages for React 
Javascript :: reactrouter 
Javascript :: What can I put in the parentheses of an if statement to make it false 
Javascript :: react router v6 wrapped routes in separate files 
Javascript :: api post to curl command converter 
Javascript :: GLTF position three.js 
Javascript :: get last day of month js 
Javascript :: jquery ajax snippet 
Javascript :: Change Name Of Function Constructor 
Javascript :: finding the smallest number other than 0 in an array javascript 
Javascript :: prevent form submit twice jquery 
Javascript :: Backbone Sync And Fetch Example 
Javascript :: disable submit button until form is fully validated 
Javascript :: without the filter() method 
Javascript :: $() in javascript 
Javascript :: routing with django and react 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =