-1

I am trying to traverse the DOM in a number of places, replacing some of the content.

jQuery('.homepage_buttons_text a[href^="http://danrobertsgroup.com/?attachment_id=1037"]').each(function(){
    jQuery(this).html("<h1 class='homepage_button_title'>Workouts</h1><span class='homepage_button_title'>Books / DVD's / Downloads</span>");
});

this works fine when doing it in the console, but isn't working when I put it in the scripts file.

I am running a child-theme and enqueuing properly I think:

function child_theme_enqueue_scripts() {
wp_enqueue_script(
    'child-scripts',
    get_stylesheet_directory_uri() . '/js/child-scripts.js',
     array( 'jquery' ),
    '1.0',
    true
    );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_scripts' );

It all loads fine. I have even called child-scripts.js in the footer and in very last place - but still no joy.

It's pretty annoying, any help appreciated.

0

Where are you using the jQuery code we see in question? If you are using it in header (head), I would recommend using:

jQuery(document).ready(function(){
    jQuery('.homepage_buttons_text a[href^="http://danrobertsgroup.com/?attachment_id=1037"]').each(function(){
        jQuery(this).html("<h1 class='homepage_button_title'>Workouts</h1><span class='homepage_button_title'>Books / DVD's / Downloads</span>");
    });
});

If you are using the code in the footer, the above replacement is still recommended and for each add_action hook you can use the priority parameter:

function child_theme_enqueue_scripts() {
    wp_enqueue_script(
        'child-scripts',
        get_stylesheet_directory_uri() . '/js/child-scripts.js',
        array( 'jquery' ),
        '1.0',
        true
    );
}
add_action( 'wp_enqueue_scripts', 'child_theme_enqueue_scripts', 30 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.