![]() ![]() Let option = document. Let select = document.querySelector('select') Let input = document.querySelector('input') let btnAdd = document.querySelector('button') We are setting the value of the input element to an empty string.As a result, it will append a new option right before the currently selected option in the dropdown list. We are calling add() method of the select element and passing the newly created option and index of the currently selected option.We are using the selectedIndex property to get the index of the currently selected option and storing it in the currentIndex variable.We are setting the value entered in the input field as the text of the option element and also changing the value to lowercase and setting it as the value of the option element.In the event handler function, we are using the createElement() method to create an option element and storing it in the option variable.We have attached the click event listener to the button element.Meta tags are used by search engines to help index and to provide relevant content in their search results. We have selected button, input, and select elements using the document.querySelector() method and stored them in btnAdd, input, and select variables respectively. Meta tags are HTML tag content that provide metadata about your website such as description. ![]() We have also included our javascript file script.js with a script tag at the bottom.We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.We will add more options using javascript. As of now, we have only 3 options in the dropdown list.The inner text for the button element is “Add”.The div element with a class of container is just a wrapper for the rest of the elements. We have a few elements in the HTML file (2 div, 1 select, 3 option, 1 input, and 1 button).
0 Comments
Leave a Reply. |