I'm trying to disable a button on my site. The JavaScript I have works in the console:
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].disabled = true;
But adding it to the page doesn't work:
add_action( 'wp_head', function () { ?>
<script>
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].disabled = true;
</script>
<?php } );
I've also tried waiting for the object to load:
add_action( 'wp_head', function () { ?>
<script>
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].addEventListener("load", disable);
function disable() {
list = document.getElementsByClassName("single_add_to_cart_button button alt");
list[0].disabled = true;
};
</script>
<?php } );
Which doesn't seem to work either. The page in question is here.