I'm trying to translate a JQuery code to Javascript because importing the library of JQuery isn't the best optimization for a website and my codes are pretty simple, even if i'm not enough skilled to do it by myself and i need the help of the community...
So here is my code
$(function() {
$('#cityselector').change(function(){
$('.city').hide();
$('.' + $(this).val()).show();
});
});
I know that in JS i may need to create a let variable that i will define by clicking on the right element and then create a function that changes the status of the element (showed or hidded)
document.getElementById('citySelector').addEventListener('click', function(){
document.getElementByClass(this).style.display = "block";
document.getElementByClass('city').style.display = "hidden";
});
I don't know how to select the right css class for each city i listed, because every element of the page has 2 class: 'city' and the name of the city like 'oxford', 'london'. The goal is to show to class we select
The html code:
<Select id="cityselector" class="selectordeville">
<option value="oxford">Oxford</option>
<option value="cambridge">Cambridge</option>
<option value="stonehenge">Stonehenge</option>
<option value="bath">Bath</option>
<option value="york">York</option>
<option value="robinhoodbay">Robin's hood's bay</option>
<option value="lakedistrict">Lake District</option>
<option value="snowdonia">Snowdonia</option>
<option value="bristol">Bristol</option>
<option value="cardiff">Cardiff</option>
<option value="glasgow">Glasgow</option>
<option value="edinburgh">Edinburgh</option>
<option value="highlands">Highlands</option>
<option value="harrypotter">Harry Potter Studios</option>
<option value="altontowers">Alton towers</option>
<option value="thorpepark">Thorpe park</option>
<option value="windsor">Windsor</option>
<option value="liverpool">Liverpool</option>
<option value="brighton">Brighton</option>
<option value="eurotrip">Eurotrip</option>
<option value="canterbury">Canterbury</option>
</Select>
Thank you very much for your help, i'm learning JS and i stil have problems to understand how to use 'this' in JS, JQuery is too "magic" simple and don't give us good habits i think.