Load an image in WordPress with jQuery

I’m developing a template page for WordPress, I need to load an image when I click a button the path is namesite.com/wordpress/test and I need to load an image

$("<img src='wp-content/themes/twentytwelve/images/loader.gif' class='loader' />").appendTo("#contact");

The problem is that the image isn’t searched in wordpress/wp-content/themes/twentytwelve/images/loader.gif but in wordpress/test/wp-content/themes/twentytwelve/images/loader.gif so I have error. How can I do?

Related posts

Leave a Reply

1 comment

  1. Prepend the img src with ‘/’ to start at the root. Ex:

    $("<img src='/wordpress/wp-content/themes/twentytwelve/images/loader.gif' class='loader' />").appendTo("#contact");