To show a hidden div when a select option is selected, you can set the value “style.display” to block.
Example
Following is the code −
DocumentThis is the Javascript
To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.
This destructing can also be used inside of a loop, so you could then structure your provinces like so using array literals
const provinces = [ ['AB', 'Alberta'], ['BC', 'British Columbia'], ['MB', 'Manitoba'], ['NB', 'New Brunswick'], ['NL', 'Newfoundland'] ]Here I am using a for…of loop to log out the alpha codes and province names.
for (const [alphaCode, province] of provinces) { console.log(alphaCode + ' - ' + province) } /* Outputs AB - Alberta BC - British Columbia MB - Manitoba NB - New Brunswick NL - Newfoundland */You can hopefully see that destructuring provides a clearer alternative to using indexes e.g. provincesArray[1][i] and const [breakfast, lunch, dinner] = ['cornflakes', 'sandwich', 'bolognese'] console.log(breakfast) // 'cornflakes' console.log(dinner) // 'bolognese' 0
In addition if you use ‘let’ or ‘const’ to define your variables you can take advantage of block scope
You could then remove these two lines
var newOption; var newTextNode;And define the variables inside of your loop instead. By using const here, we get an entirely new variable definition for each iteration of the loop.