<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var num=$(this).attr('rel');
$('p').each(function(){
$(this).hide();
});
$('#p'+num).show();
});
});
</script>
</head>
<body>
<p id="p1">This is a paragraph 1.</p>
<button rel="1">Toggle between hide(1) and show(1)</button><br>
<p id="p2">This is a paragraph 2.</p>
<button rel="2">Toggle between hide(2) and show(2)</button><br>
<p id="p3">This is a paragraph 3.</p>
<button rel="3">Toggle between hide(3) and show(3)</button><br>
<p id="p4">This is a paragraph 4.</p>
<button rel="4">Toggle between hide(4) and show(4)</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a").click(function(){
var num=$(this).attr('rel');
$('p').each(function(){
$(this).hide();
});
$('#p'+num).show();
});
});
</script>
</head>
<body>
<p id="p1">This is a paragraph 1.</p>
<a href="#" rel="1">Toggle between hide(1) and show(1)</a><br>
<p id="p2">This is a paragraph 2.</p>
<a href="#" rel="2">Toggle between hide(2) and show(2)</a><br>
<p id="p3">This is a paragraph 3.</p>
<a href="#" rel="3">Toggle between hide(3) and show(3)</a><br>
<p id="p4">This is a paragraph 4.</p>
<a href="#" rel="4">Toggle between hide(4) and show(4)</a>
</body>
</html>