Skip to content

Tag: html

JavaScript – capture img tags src in variable

im trying to store an image in HTML that comes from a url source in a variable using JavaScript. Could someone show me what code is required? i have started it off… Answer You can use the src property. You can also use the src property to set a new URL for the image if you want to replace it.

How to use Document Object Model in TypeScript?

I’m extremely new to typescript (and JavaScript for that matter), I think I’ve mastered the fundamentals when it comes to TypeScript (variables, arrays, if/else statements etc) but I would like to add functionality to my static webpages and I can’t keep using console logs obviously. My exper…

Loop through a nested JSON object

I’m looking for a solution to loop through a nested JSON object in pure JS. Indeed I’d like to console.log every item and each of its properties. Answer You are accessing an object’s value using its key in json_object[item] so just keep drilling down into the object.

How to give autofocus to a element when another element has it?

I am trying to give a textarea (which is added when you click on a button) autofocus with the autofocus attribute, but when I do that it doesn’t works and I get this message on the console: So now the question is: How can I get the focus to the textarea when some other element already has it? Answer Giv…