Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to use search/filter for HTML Divs generated from JSON data using JavaScript

// Links Filter
var input = document.getElementById("search-filter-cards");
input.addEventListener("input", searchFilterDivsMenu);

function searchFilterDivsMenu(e) {
  const filter = e.target.value.toUpperCase();
  const cards = document.querySelectorAll("#links-list .card");
  cards.forEach(card => {
    var a = card.querySelector("a");
    // console.log(filter, "|", a.textContent.toUpperCase(), "|", a.textContent.toUpperCase().indexOf(filter))
    card.hidden = !a || (filter && a.textContent.toUpperCase().indexOf(filter) === -1);
  })
}

// JSON Data for each links
const maincards = {
  "linksList": [{
      'name': 'Java Bookmarks',
      'title': 'Java Bookmarks',
      'favicon': '../assets/links-favicons/java-bookmarks.png',
      'url': '#',
      'tags': 'Login, Logout, Log-in, Log in, Log-out Log out',
      'linkattributes': 'rel="noopener noreferrer" target="_blank"'
    },
    {
      'name': 'Chrono',
      'title': 'Chrono',
      'favicon': '../assets/links-favicons/chrono.ico',
      'url': '#',
      'tags': 'Login, Logout, Log-in, Log in, Log-out Log out',
      'linkattributes': 'rel="noopener noreferrer" target="_blank"'
    },
    {
      'name': 'Kanban (May)',
      'title': 'EDEN Kanban',
      'favicon': '../assets/links-favicons/kanban.ico',
      'url': '#',
      'tags': 'Login, Logout, Log-in, Log in, Log-out Log out, Kanban board',
      'linkattributes': 'rel="noopener noreferrer" target="_blank"'
    },
  ]
};

const createMainCardLinks = ({
  name,
  title,
  favicon,
  url,
  tags,
  linkattributes
}) => `
    <div class="card link-container">
      <img class="link-img" src="${favicon}"/>
      <a class="link-title stretched-link" href="${url}" ${linkattributes} title="${title}">${name} <span class="h-0">${tags}</span></a>
    </div>
  `;

const links = maincards.linksList.map(createMainCardLinks);
document.getElementById("load-json-data").innerHTML = links.join("")
Comment

How to use search/filter for HTML Divs generated from JSON data using JavaScript

.h-0 {
  display: none;
}
Comment

How to use search/filter for HTML Divs generated from JSON data using JavaScript

<input id="search-filter-cards" type="text" autocomplete="off" placeholder="Type here to search">
<div id="links-list">
  <div class="link-headers"><a class="mb-0">Sample Links</a></div>
  <div id="load-json-data"></div>
  <div class="card link-container">
    <img class="link-img" src="../assets/links-favicons/plus.ico" />
    <a class="link-title stretched-link" href="#" rel="noopener noreferrer" target="_blank" title="Plus">Plus <span class="h-0">Quick Links</span></a>
  </div>
  <div class="card link-container">
    <img class="link-img" src="../assets/links-favicons/google.ico" />
    <a class="link-title stretched-link" href="#" rel="noopener noreferrer" target="_blank" title="Google">Google <span class="h-0">Quick Links</span></a>
  </div>
</div>
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: Extract and convert from JSON by Regex 
Javascript :: Save multiple radios checked on LocalStorage 
Javascript :: adding to an array in js 
Javascript :: python regex consecutive characters 
Javascript :: settimeout and create directory nodejs 
Javascript :: assignment is to create a small website using NestJS in the backend and basic HTML CSS in the frontend 
Javascript :: sending api with limited fields in express 
Javascript :: How can I configure multiple sub domains in Express.js or Connect.js 
Javascript :: upload node js 
Javascript :: filter a object array tree javascript 
Javascript :: No enum constant datepicker react native 
Javascript :: Custom Delimiter For Mustache.js 
Javascript :: Import Variable From Module In JavaScript 
Javascript :: get value from createReadStream 
Javascript :: phaser set mass 
Javascript :: Creating New Transaction Object for blockchain 
Javascript :: chrome page transitions 
Javascript :: JavaScript: Cycle through three-state checkbox states 
Javascript :: what does the text before an object stand for in js 
Javascript :: como hacer un contador de tiempo en javascript 
Javascript :: nesjs rest api 
Javascript :: Dependency Injection in Node.js 
Javascript :: check token balance of an address using web3 
Javascript :: var logEvenNums = function(num) {}; 
Javascript :: adding number upto n , adding number, fastest number addding 
Javascript :: file path to blob javascript 
Javascript :: How to fix prettier messing up your HTML on save 
Javascript :: how to scroll element in javascript 
Javascript :: change your favicon in javascript 
Javascript :: fs.writefile promise 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =