Reputation: 496
I am working on a site where i have arranged my pages in directories except for the index page. My problem occurs when i use jquery to append images to a div within a section of the pages. It shows on the index page but not on other pages (which are directories). I understand why but not sure how i can fix it.
Is there a way to fix this without having to remove my other files from directories?
var $img1 = $('<img src="images/test1.jpg" />');
var $img2 = $('<img src="images/test2.jpg" />');
$('#container').append($img1, $img2);
Please note that the above code is also in a separate directory
Upvotes: 0
Views: 105
Reputation: 689
You can write the full link including domain name:
var $img1 = $('<img src="http://www.yoursitename.com/images/test1.jpg" />');
Upvotes: 0
Reputation: 253308
Assuming that your images
folder is located within the root directory of your website, you could just make the src
attribute root-relative:
var $img1 = $('<img src="/images/test1.jpg" />');
var $img2 = $('<img src="/images/test2.jpg" />');
$('#container').append($img1, $img2);
(Note the /
added to the beginning of the src
attribute).
Reference:
Upvotes: 2