Using CSS only
To achieve this effect using pure CSS, you can utilize the :hover
pseudo-class. When hovering over the "View Rows" element, you can change the display property of the ".records" class to block.
.records {
display: none;
}
.view:hover .records {
display: block;
}
<div>
<li>Add Rows</li>
<li>DeleteRows</li>
<li class="view">View Rows
<ul class="records">
<li>View New Records</li>
<li>View Old Records</li>
</ul>
</li>
</div>
Implementing with Javascript
If you prefer using JavaScript for interactivity, there is an example below that demonstrates how to achieve the same hover effect using event listeners and DOM manipulation techniques. This method provides more flexibility for customization compared to the CSS-only approach.
var records = document.querySelectorAll(".records");
var view = document.querySelectorAll(".view")[0];
view.addEventListener("mouseover", function() {
records.forEach(e => {
e.style.display = "block";
});
});
view.addEventListener("mouseleave", function() {
records.forEach(e => {
e.style.display = "none";
});
});
.records {
display: none;
}
<div>
<li>Add Rows</li>
<li>DeleteRows</li>
<li class="view">View Rows
<ul class="records">
<li>View New Records</li>
<li>View Old Records</li>
</ul>
</li>
</div>
Utilizing jQuery
For those who prefer working with jQuery, an alternative method is presented below. By using the .hover()
function, you can easily show and hide the list items within the "View Rows" section when hovering over it.
$(".records").hide();
$(".view").hover(function() {
$(".records").show();
});
$(".view").mouseout(function() {
$(".records").hide();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<li>Add Rows</li>
<li>DeleteRows</li>
<li class="view">View Rows
<ul class="records">
<li>View New Records</li>
<li>View Old Records</li>
</ul>
</li>
</div>