JS Function in HTML says “buy is not defined”, but it is?

I am trying to make a little element that looks like a button execute a js function I defined named “buy()”. For an odd reason, it works for some and doesn’t for others. All buy() does is show a modal.

I tried to put the content of the function in the onclick property but it contains quotes, which would make it go onclick=”$(“.modal”).show()” and i can’t use single quotes, because this is all being echoed by a php script aswell. I tried using backslashes since that is what I am used to in other languages but those don’t work.

buy():

function buy() {
   $(".modalBackground").show();
   $("#promptPurchase").show();
}

html element using buy():
<a class="Button" onclick="buy()">Buy</a>

The script tag is below the a, and when I put it above it, it still returns the same issue.