How can I write the content of a variable in image src while using document.getElementById?

I have the following code document.write("<img src=./", i, ".png width=’100px’ height=’100px’>"); document.write("<img src=./", x, ".png width=’100px’ height=’100px’>"); document.write("<img src=./", y, ".png width=’100px’ height=’100px’>");` and I want to use the src in getElementById(myImg).InnerHTML. I tried this document.getElementById("myImg").innerHTML.src = "./", i, ".png width=’100px’ height=’100px’>"; But It’s not working What is the proper way to write it? >Solution… Read More How can I write the content of a variable in image src while using document.getElementById?

How to display text input after submitting button in HTML and Javascript

I have an input box that I am typing into and a submit button. I want to display whatever is typed into the input box in a blank pre-existing <p> tag. How can I do this? I currently have this code: <label for="moveData">Enter data</label> <input type="text" id="moveData" name="moveData"><br> <button id="btn" type="button">Move the data</button> <script> document.getElementById("btn").onclick… Read More How to display text input after submitting button in HTML and Javascript

How can I use javascript to create a div with elements inside of it?

I would like to create the following structure: <div> <label>Label:</label> <p>This text should be right beside the label</p> </div> So the results would look something like: Label: Here is the text I have tried doing using the following: label_element = document.createElement(‘label’) p_element = document.createElement(‘p’) label_node = document.createTextNode(‘text’) p_node = document.createTextNode(‘text2’) label_element.appendChild(p_element) document.getElementById(‘anchor’).appendChild(‘label_element’) The above returns:… Read More How can I use javascript to create a div with elements inside of it?

Uncaught (in promise) TypeError: img.src is not a function

I got this error while working on javascript what I wanted to do is that I want to add img src in javascript through data fetched using an API my Javascript code is const img = document.getElementById("image"); const input = document.querySelector("input"); const weather = document.getElementById("el"); const form = document.querySelector("form"); form.addEventListener("submit", (el) => { el.preventDefault(); const… Read More Uncaught (in promise) TypeError: img.src is not a function

Why does it show the tag's type when I use getElementById method in javascript and html

I used getElementById method to return the tag’s element but it returns the tag’s type ?! <!DOCTYPE html> <html> <head> <title>Title</title> </head> <body> <p id =”textlabel”></p> <script> function bonef(){ var a = document.getElementById(“textlabel”); var b = “1”; a.innerHTML += b; } </script> <button onclick=”bonef();”>1</button> </body> </html> It shows "[object HTMLParagraphElement]1" but I want "1" !… Read More Why does it show the tag's type when I use getElementById method in javascript and html

How can I assign value of get element by id into array in Javascript?

as you can see I have a lot of repetitive code below… var c0 = document.getElementById(‘c0’); var c1 = document.getElementById(‘c1’); var c2 = document.getElementById(‘c2’); var c3 = document.getElementById(‘c3’); var c4 = document.getElementById(‘c4’); var c5 = document.getElementById(‘c5’); var c6 = document.getElementById(‘c6’); var c7 = document.getElementById(‘c7’); var c8 = document.getElementById(‘c8’); var c9 = document.getElementById(‘c9’); var c10 =… Read More How can I assign value of get element by id into array in Javascript?

getElementById but unique for each component

I have reusable component on which I need to access its ‘id’ for scrolling: var slider = document.getElementById(‘slider’); slider.scrollLeft = slider.scrollLeft – (3); The Id is declared: <div id=’slider’ className="scroll-smooth" > I know this is wrong and it obviously fails whenever more than one such component is used, as only the the first component’s slider… Read More getElementById but unique for each component