I'm trying to incorporate javascripts in my wordpress posts. I've previously done it by just adding it to the post in the wordpress editor, but I've heard the better way is to add it to a js directory in my theme folder and then make it accessible as explained here:
http://www.wpbeginner.com/wp-tutorials/how-to-move-javascripts-to-the-bottom-or-footer-in-wordpress/
I've gotten this to work such that an alert comes up when a button is pressed. But when I try to get an element by its id as follows, it can't be found: document.getElementById('InOrCm').value = "in";
Any suggestions?
Thanks, Sam
Update: turned out was an html error. Next step is to make the javascript on work on certain pages. I've been trying to do this with the below code, but crashes my wordpress, suggestions?
function wpb_adding_scripts() { is_page( 'javascript-testing-2-2' ) { wp_register_script('HeightComparisonTool', get_template_directory_uri() . '/js/HeightComparisonTool.js','','1.1', true); wp_enqueue_script('HeightComparisonTool'); } } add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );