Need jQuery onClick To Change Button Text and Background-Color

sharingsunshine
sharingsunshine used Ask the Experts™
on
I am on Wordpress 4.9.8 and WooCommerce 3.5.4.

I am trying to get a button using jquery to change background color and change the text in the button onClick.  I have come up with this code but when I try to save it I get an error.  

JavaScript error: ReferenceError: jQuery is not defined on line 6

Open in new window

this is line 6
e.preventDefault();

Open in new window


<script type="text/javascript">

jQuery(function() {
	jQuery('#result').text(listCookies);
	jQuery('#cook').click(function(e) {
		e.preventDefault();
		document.cookie = "wantmembership=1; path=/";
              jQuery(this).css('background-color','green');
              jQuery(this).text("I Have Membership");
		jQuery('#result').text(listCookies);
	});
	
	
});

</script>

Open in new window


I am very new to jQuery.

Please tell me how to fix this code to change the background-color and the text both.

Thanks,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
The 'jQuery is not defined' error usually means that you haven't loaded the jQuery library. Check the source of your page to make sure you're referencing a value jQuery libray.

Author

Commented:
That did it!  Thanks for the help.

I added this line and they both worked using this code

wp_enqueue_script('jquery')

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial