I currently have the following code implemented on my webpage:
var menuBreadcrumb = document.getElementById('menu-breadcrumb');
var counta = $("#menu-breadcrumb a").length;
//alert(counta);
if (counta >= 2) {
let mbcElement = '<a class="mbc-link-back" href="#" data-menu-item-id="">...</a>';
menuBreadcrumb.insertAdjacentHTML('beforeend', mbcElement);
}
.mbc-link-back {
color: #0066cc;
text-decoration: none;
}
#menu-breadcrumb a+a::before {
color: #222;
content: '>';
cursor: default;
padding: 0 3px;
}
<div id="menu-breadcrumb">
<a href="">Demo 1</a>
<a href="">Demo 2</a>
<a href="">Demo 3</a>
<a href="">Demo 4</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
The purpose of this code is to display the first and last anchor tags if there are more than two anchors, with clickable ellipsis in the middle.
For example, with more than 2 anchors, the expected output would be:
Demo1 > ... > Demo4
If there are only 2 anchor tags, the output should be:
Demo1 > Demo2