3

Can I call a JavaScript function in Wordpress like this?

<input type="button" value="" class="domain_submit" onclick="callGetDomain();">

Where should I put my JavaScript? at footer.php? or what would be the proper way to achieve something like this?

I put my script in footer.php, then I called the function like as I mentioned but no use?

1
  • 1
    You shouldn't put your script anywhere, you should include it with wp_enqueue_script and you should use proper event listeners. Commented May 28, 2015 at 6:07

1 Answer 1

6

Yes you can use onclick="callGetDomain();" and for the function definition, use a separate js file and include that file using wp_enqueue_script(), which is the proper way to call js files in Wordpress. Check this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.