How can I print the output as 17 in 1 days 21 in 2 days 23 in 3 days and not 17 in 0 days 21 in 1 days 23 in 2 days Answer Since the index starts from 0, you just need to add one (1) when you print it in your console.log() (${i+1})
Tag: element
How to get index of an empty element of an array?
I have a JavaScript array with some empty (maybe null or undefined) elements. I need to find those empty indexes (1 and 3). But my solution is not working: Snippet: Answer Use a blank string to compare to get the answer you desire. If you also want to check for undefined you can use logical or to check both of
How to get certain element (using JavaScript) from HTML with similar classes?
How can I get one certain element from HTML using JavaScript. I have this code. I want to write “Text From Second Block”. If I write this code I will get “Text From First Block” Answer instead of using queryselector you can use getElementsByClassName() and instead of enter the index number of your tag
Get parent data element from dragged element – Drag en drop function
I am trying to retrieve a parent data attribute data-date of the dragged object in JavaScript. So i want to receive the data-date attribute <td> from where the div “drag me” was dragged from. HTML example: I am able to retrieve the dropped data-date attribute, but cant figure out how to retrieve the dragged from data-date attribute. JS From and
How can i get an ID from a select multiple using Element?
I have a select for persons assigned to a proyect, so i need to send the ID from the object selected to a function i tried: Array persons: Method The pid (person id) is undefined and i can’t find a solution for my case, i will appreciate help and comments. Answer You are facing what is referenced in Vue.js documentation
How to appendChild(element) many times. (The same element)
My question is: Is that possible to add the same element without rewriting the same variable. I am creating a slider, and i need to append a div with a class slide-el into block slider. Here is a part of code The problem is that I can’t append the same element that many times. It just creates one element instead
Javascript get element index position in DOM array by class or id
My situation Now I want to return the array item key – position of the element in the array – ( for example domElements[34]) searching in the array for the element with id=”asd”. How can I achieve this? What if instead of ID I want to search trough class=”asd hey” ? Any help appreciated, thank you! NB: Not in jquery,
document.querySelector multiple data-attributes in one element
I’m trying to find an element with document.querySelector which has multiple data-attributes: I thought about something like this: But it does not work. However, it works well, if I put the second data-attribute in a child-element like: So, is there an option to search for both attributes at once?I’ve tried several options but I don’t get it. Answer There should
Remove first child in javascript
I’m trying to remove the first li in an ol using the DOM removeChild(). But for some reason it doesn’t work. This is my javascript: And this is my HTML: I tried alerting the childNodes[0], and it returns [Object Text], which seems a bit weird, when I was expecting just the object. Hope I’ve been clear. Answer Between the <ol
How to remove elements that were fetched using querySelectorAll?
This seems like something that would have a quick answer, but I can’t find one. Maybe I’m searching the wrong terms? No libraries please, though I don’t need cross-browser fallbacks, I’m targeting all the latest versions on this project. I’m getting some elements: This is working, but how do I now delete these elements? Do I have to loop through