I have two buttons with different ids. I want to hide specific paragraph when button with similar id is clicked.
Here's my code
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var id = $(this).attr("id").replace('test', '');
$('.p #'+id+'').hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<div class="gallery">
<div class="picture">
<p id="1">This is a paragraph.</p>
<p id="2">This is another paragraph.</p>
</div>
</div>
<button id=test1>Click me1</button>
<button id=test2>Click me2</button>
</body>
</html>
As you can see if i click button with id "test1" I want to hide the paragraph with id "1". But It's not working.