Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to make a sidebar that dynamically create content from an object result in javascript
Object { Chemistry: Array[3], Maths: Array[1], Physics: Array[2] }
And also there are some element in Array above
I know this isn't the best way to do it, but this is an idea on how to make it:
var obj = {'Chemistry':['Chemistry1','Chemistry2','Chemistry3'],'Maths':['Maths1'],'Physics':['Physics1','Physics2']};
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function ulCreator(obj){
var menu = document.createElement("UL");
for (var key in obj) {
var node = document.createElement("LI");
var textnode = document.createTextNode(isNumber(key) ? obj[key] : key);
node.appendChild(textnode);
if(Array.isArray(obj[key])){
node.appendChild(ulCreator(obj[key]));
}
menu.appendChild(node);
}
return menu;
}
document.getElementById("main").appendChild(ulCreator(obj));
<div id="main">
</div>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 days ago.
Improve this question
Having this json https://apimeta.paz.cl/
How can I filter it to create a new json when I just have objects where created_time property value is grater than 1600000?
I'm trying with this but it's not working as expected so far...
var data = JSON.parse(myjson)
var newjson = [];
data.forEach(function (entry, i) {
entry.forEach(function (changes, i) {
changes.forEach(function (changes, i) {
if (item.value.created_time >= 16000){
newjson.push(entry);
}
});
});
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
hello i'm work for question system i want to add many answers in a one question in a one value
html
<input id="an" placeholder="test" type="text"/><a id="wo" style="display:none;">done test</a><button id="bt">Submit</button>
javascript
const an = document.getElementById("an");
const bt = document.getElementById("bt");
bt.addEventListener("click", () => {
if (an.value.toLowerCase() === "test") { // I want create many value in here.
bt.style.display = "none";
an.style.display = "none";
document.getElementById("wo").style.display = "initial";
} else {
bt.innerText = "Wrong!"
bt.style.background = "red";
}
});
I hope this answer is what you are looking for:
You can make an array with your answers, and then check to see if the given answer is inside the array.
const array = ['test', 'test2', 'test3'];
if (array.includes(an.value.toLowerCase() ) )
...
Something else, you are missing a semicolon in your else { ... }.
bt.innerText = "Wrong!";
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
with this code I managed to create a child to each of the elements of the Node list via QueryselctorAll but I need to retrieve the tille ((document.queryseletor(....).title) works but not dynamically...) of the parent div dynamically as a variable to enter it in the innerHTML of the child. Do you have an idea ?
function onloaddiv() {
for (const item of document.querySelectorAll('.mat_option')) {
divp = document.createElement("div");
var2 = document.querySelector(".mat_option").title;
divp.innerHTML= "" + var2;
item.append(divp);
}
}
From your description I'm not 100% sure what you'd like to achieve, but maybe this?
function onloaddiv() {
for (const item of document.querySelectorAll('.mat_option')) {
divp = document.createElement("div");
var2 = item.title;
divp.innerHTML= "" + var2;
item.append(divp);
}
}
You don't need to query selector once again, you already have item in your loop
function onloaddiv() {
for (const item of document.querySelectorAll('.mat_option')) {
divp = document.createElement("div");
divp.innerHTML = item.title;
item.append(divp);
}
}
It doesn't work "dynamically", as you say, because document.querySelector(...) returns only first element it could find.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
//I need to do this with for
var name = ["Jhon", "Anne", "Ewreck", "Nine"];
for( var i = 0 ; i < name.length ; i++ ){
name[i].push(name[i].toUpperCase());
console.log(name[i]);
}
Try this
let name = ["Jhon", "Anne", "Ewreck", "Nine"];
let nameUpper = name.map( x => x.toUpperCase() )
console.log(nameUpper);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
im making a timetable that when opened gives me the zoom links to my classes and tells me what classes i have in the day.
function myFunction() {
var d = new Date();
var n = d.getDay()
document.getElementById("demo").innerHTML = n;
if (n == 1) {
document.writeln("Monday")
document.writeln("you have 2 classes today X and Y and the zoom links are: ...);
}
Don't use document.write, but append elements to some wrapper:
(function () {
var wrapper = document.getElementById('wrapper');
var links = {
'http://example.com': 'Example1',
'https://example.com': 'Example2'
};
for (link in links) {
tag = document.createElement('a');
tag.setAttribute('href', link);
tag.innerText = links[link];
wrapper.appendChild(tag);
}
})();
<div id="wrapper"></div>