averainy's Blog

averainy

04 Sep 2023

Use Jquery Filter Same Elements with the same attributes and Hide Them

Use jquery to filter elements with the same attributes and hide them:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
	$("a").each(function(){
		let href = $(this).attr('href');
		$(`a[href="${href}"]`).slice(1).hide();
	}
	);
});
</script>
</head>
<body>

<a href="a">a</a>
<a href="b">b</a>
<a href="a">a</a>
<a href="d">d</a>

</body>
</html>

Categories