Phyllis McMahon
Phyllis McMahon

Reputation: 11

Why doesn't jQuery work on a WordPress page?

I am working on my website. jQuery does not work on the WordPress page. Here is my code:

<script>
  color = $("#colorPicker").val()
</script>

Error: Uncaught TypeError: $ is not a function`

I'm using the Header and Footer Scripts Plugin.

Upvotes: 1

Views: 44

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337714

Wordpress jQuery installations use the jQuery keyword instead of $. Change your code to this:

<script>
  color = jQuery("#colorPicker").val();
</script>

Alternatively, use the document.ready event handler and alias the jQuery instance passed in the argument to the function:

<script>
  jQuery($ => {
    color = $("#colorPicker").val();
  });
</script>

Upvotes: 1

Related Questions