Skip to content

Instantly share code, notes, and snippets.

@avipars
Created October 3, 2021 15:03
Show Gist options
  • Save avipars/c5993974ee1d9c6d609e9ccccc69e774 to your computer and use it in GitHub Desktop.
Save avipars/c5993974ee1d9c6d609e9ccccc69e774 to your computer and use it in GitHub Desktop.
JS create button
function createTrends() {
const itemLists = ["microSD Card", "Steak Knife", "ButtonDown Shirts"];
const hebrewLists = ["סכין סטייק", "כרטיס זיכרון", "חולצה מכופתרת"];
var hebTerm, mainTerm;
let trend = document.getElementById("trending");
var j = 0;
itemLists.forEach((k) => {
j++;
mainTerm = k;
hebTerm = hebrewLists[j];
console.log(j + mainTerm + hebTerm);
let btn = document.createElement("button");
btn.classList.add("btn");
btn.classList.add("btn-outline-info");
btn.classList.add("trend");
btn.id = "trend_" + j;
btn.title = hebTerm;
btn.textContent = hebTerm; //innerText
btn.addEventListener("click", function () {
popularSearch(mainTerm);
console.log("clicked" + mainTerm + j);
});
trend.appendChild(btn);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment