Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 577
Mitro Avatar asked Dec 19 '12 13:12

Mitro


1 Answers

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");
like image 86
Syon Avatar answered Sep 27 '22 22:09

Syon