I have a wordpress website and i want to add a class "myclass" to all anchor elements with JQuery. This wordpress installation does not have any plugin enabled, so its a default installation.
I enqueue TEST.js file with the following command at the bottom of the functions.php file of my theme (Hello Elementor)
add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_script('jquery'); // Explicitly telling wordpress to load jquery
wp_enqueue_script(
'fixamea', // name your script so that you can attach other scripts and de-register, etc.
get_template_directory_uri() . '/TEST.js', // this is the location of your script file
array('jquery')
);
}
And the file TEST.js is the following
jQuery(document).ready(function($){
$('a').addClass('myclass');
console.log("running");
})
The console log "running" appears but the class 'myclass' is not added to any Anchor elements. What could be wrong?