Below is my HTML code and the javascript part in the tag is not working. Even if I paste the JavaScript code to external JS file - script.js, it's not working. I tried writing it separately in script.js like this, but that also did not work for me:-
document.getElementById(".button").addEventListener("click", function(){
document.querySelector(".popup").style.display = "flex";});
document.getElementById(".close").addEventListener("click", function(){
document.querySelector(".popup").style.display="none";});
here is the HTML code with JavaScript code written within script tags
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div class="container">
<h1>Popup for adding/editing Expertise details</h1>
<a href="#" class="button">Add/Edit</a>
</div>
<div class="popup">
<div class="popup-content">
<div class="register">
<form method="post" id="register" action="">
<label> Expertise Area: </label><br>
<input type="text" name="Fname" id="name" placeholder="Enter your Expertise Area"><br><br>
<label> Experience: </label><br>
<label for="quantity">No. of months:</label>
<input type="number" id="quantity" name="quantity" min="1" max="11">
<label for="quantity">No. of years:</label>
<input type="number" id="quantity" name="quantity" min="1" max="50"><br><br>
<label> Rates </label>
<label> Remote: </label><br>
<select id="ph">
<option>per hour</option>option>
<option>per topic</option>option>
<option>per chapter</option>option>
</select>
<label for="quantity">Amount in Rs.:</label>
<input type="number" id="quantity" name="quantity">
<label> Center: </label><br>
<select id="ph">
<option>per week</option>option>
<option>per month</option>option>
</select>
<label for="quantity">Amount in Rs.:</label>
<input type="number" id="quantity" name="quantity">
<label> Learner's Place: </label><br>
<select id="ph">
<option>per class</option>option>
<option>per hour</option>option>
</select>
<label for="quantity">Amount in Rs.:</label>
<input type="number" id="quantity" name="quantity"><br>
<label> My Place: </label><br>
<select id="ph">
<option>per class</option>option>
<option>per hour</option>option>
</select>
<label for="quantity">Amount in Rs.:</label>
<input type="number" id="quantity" name="quantity"><br><br>
<a href="#" class="button">Submit</a>
<img src="close.png" class="close" alt="Close">
</form>
</div>
</div>
</div>
<script>
document.getElementById(".button").addEventListener("click", function() {
document.querySelector(".popup").style.display = "flex";
});
document.getElementById(".close").addEventListener("click", function() {
document.querySelector(".popup").style.display = "none";
});
</script>
</body>
</html>
getElementByIdtakes the value of an element's ID attribute. There is no element in your code with an ID of ".button" or "button" for that matter. Note also your option elements are incorrectly closed</option>option>is invalid HTML.