Selecting an element ID that was created in an innerHTML variable

How do I select the textfield element "member-name"? function revealPaywall (){ const paywall = document.getElementById(‘paywall’) const name = localStorage.getItem("value"); //TO WRITE MULTILINE HTML IN JS, USE BACKTICKS “ TO CREATE A TEMPLATE LITERAL if (localStorage.getItem("value") === null){ paywall.innerHTML = ` <h1>This Is An Example Of A Paywall<h1> <p>If you enter a name, it will be… Read More Selecting an element ID that was created in an innerHTML variable

javascript: querySelector containing @ symbol is invalid

I have an element with a className containing an @ symbol. Such as <div class="modify@s"> I can easily style this via a css selctor such as .modify\@s But I can’t use this selector to target the element via querySelector in javascript. document.querySelector(‘.modify@s’) document.querySelector(‘.modify\@s’) ‘… is not a valid selector" How can I select this element… Read More javascript: querySelector containing @ symbol is invalid

create fn for chenge CSS style in js

I need to create a function for changing the CSS Style like the below: (because I use this several times in my code) document.querySelector(‘.number’).style.width = ’30rem’; document.querySelector(‘.number’).style.color = ‘green’; document.querySelector(‘body’).style.backgroundColor = ‘green’; can use like displayStyleNumber function: const displayStyleNumber = (classElement, property, value) => { const displayCssStyle = `document.querySelector(‘${classElement}’).style.${property} = ‘${value}’;` return displayCssStyle; } when… Read More create fn for chenge CSS style in js

Javascript indexOf a list for a targeted event in a unordered list giving the wrong index

I am trying to get the index number of a ‘li’ element of a ‘ul’ from the html. To do this I change the ‘ul’ into a list to get his children with: […ul.children] However when I target any of the children I get a -1 as index instead of the correct index. How to… Read More Javascript indexOf a list for a targeted event in a unordered list giving the wrong index

Javascript document.querySelector just need the value

my webpage excerpt looks like this <div class="current-timestamp" style="–duration:"00:13:19"; –absolute-position:"00:00:00";"><span class="position"></span><span class="divider"></span><span class="duration"></span></div> i try to get the value 00:13:19 via the chrome console with this command document.querySelector(".current-timestamp"); however i receive the full code like above. What do i need to do to just receive "00:13:19" ? >Solution : It’s not common to store the… Read More Javascript document.querySelector just need the value

Is there any advantage to using Array.from with a querySelectorAll()

In a tutorial I saw the following: Array.from( template.querySelectorAll(‘.hw-text’) ) .forEach( n => n.textContent = hwMsg ); But the following line would also work. template.querySelectorAll(‘.hw-text’).forEach( n => n.textContent = hwMsg ); Now I wonder why in the tuturial Array.from is used and what advantage you get from it. >Solution : forEach was not part of… Read More Is there any advantage to using Array.from with a querySelectorAll()

Creating HTML/Javascript Modal with dynamic text

I am learning Javascript and my project contains 3 buttons that open a modal. Everything works fine, however I want to reuse the modal and replace the modal text depending on which button is clicked. My HTML is below: <body> <button class="show-modal" id="btn-1">Show modal 1</button> <button class="show-modal" id="btn-2">Show modal 2</button> <button class="show-modal" id="btn-3">Show modal 3</button>… Read More Creating HTML/Javascript Modal with dynamic text