It's generally not a good idea to use inline event handlers.
Instead, you can easily attach an event handler to all buttons in jQuery like:
$('ul button').click(function(){
$(this).closest('li').toggle( "slide" );
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li><button>Button 1</button></li>
<li><button>Button 2</button></li>
<li><button>Button 3</button></li>
</ul>
In case, you still want to use inline event handlers then you can simply pass this
inside the handler like:
<button onclick="test(this)">Button</button>
and update your javascript function like:
function test(obj) {
$(obj).closest('li').toggle("slide");
}
Demo:
function test(obj) {
$(obj).closest('li').toggle("slide");
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li><button onclick="test(this)">Button 1</button></li>
<li><button onclick="test(this)">Button 2</button></li>
<li><button onclick="test(this)">Button 3</button></li>
</ul>