Need some help with jQuery as I am still learning. I currently have a dropdown navbar menu that shows on hover. Everything is working fine, but I want to change it so the dropdown appears on click instead of hover. Additionally, I would like to hide the dropdown when clicking outside of the menu. I do not use any frameworks for this.
<ul class="tc-navigation">
<li class="active">
<a href="home.php">HOME</a>
</li>
<li>
<a id="er">SERVICES</a>
<ul>
<li class="round"><a id="err">Transportation<i class="fa fa-angle-right"></i></a>
<ul>
<li class="round"><a href="bus.php">Bus</a></li>
<li class="round"><a href="taxi.php">Taxi</a></li>
<li class="round"><a href="air.php">Air</a></li>
</ul>
</li>
<li class="round"><a href="car_rental_agencies.php">Car Rental Agencies</a></li>
<li class="round"><a href="driving_licence.php">Driving Licence</a></li>
</ul>
</li>
<li>
<a id="er">ABOUT US</a>
<ul>
<li class="round"><a href="about_us.php">Who We are</a></li>
<li class="round"><a href="our_vision.php">Our Vision</a></li>
<li class="round"><a href="photo_gallery.php">Photo Gallery</a></li>
</ul>
</li>
<li class="round"><a href="contact.php">CONTACT</a></li>
</ul>
CSS
.tc-navigation li>ul {
list-style: none;
margin: 0;
padding: 0;
top: 120%;
border-top: 2px solid;
border-radius: 0;
position: absolute;
width: 190px;
visibility: hidden;
opacity: 0;
background: #fff;
z-index: 10;
}
.tc-navigation li ul li {
float: none;
border-bottom: 1px solid #e1e1e1;
}
.tc-navigation li ul li:last-child {
border: 0;
}
.tc-navigation li ul li a {
width: 100%;
color: #444;
padding: 15px;
text-transform: capitalize;
text-align: center;
}
.tc-navigation li:hover>ul {
visibility: visible;
opacity: 1;
top: 100%;
}
.tc-navigation li ul li a:hover {
color: #fff;
}
.tc-navigation li ul li a:hover i {
color: #fff;
}
.tc-navigation li ul li a i {
color: #666;
position: absolute;
right: 10px;
top: 50%;
margin: -7px 0 0;
}
/* Sub Menu */
.tc-navigation li>ul li ul {
left: 110%;
top: 0!important;
}
.tc-navigation li ul li:hover>ul {
visibility: visible;
opacity: 1;
left: 100%;
}