Reputation: 35
i have image in images\a.jpg now my script is in js\a.js images and js dir are under document root www dir
in script a.js i have :
var provider_img = $(this).attr('src'); \\value of provider_img = images\a.jpg
title: '<img src=..\provider_img />',
but the image is not getting shown in title box.Please help me out
Upvotes: 0
Views: 134
Reputation: 76405
mgraph is right, all urls use the UNIX path separator. Since you're using backslash I'm assuming you're working on a windows machine. Chances are the windows path separator will cause you headaches in the future if you don't get into the habit of escaping the backslashes:
..\newDir === ..[new line]ewDir
..\\newDir === ..\newDir as you want it expected
You also might want to concatenate variable values into a string, rather then using the variable name as a string: <img src="/../'+imgVar+'"/>
.
Edit
Brian Warshaw is right, if what you want is the correct path to the image, your path should start from the same basis as the js src path. If your script tag has a src attribute like /js/script
, the image tags should have a matching path: /images/picture.jpg
. Your script isn't going to look for the file, so the path base should be the document root, not the script location. (well spotted Brian, credit to him)
Upvotes: 1
Reputation: 22984
Are you saying that you have:
Document root
--> /js/
--> /images/
If so, instead of trying to do relative paths, do an absolute path, and refer to the image at /images/a.jpg
.
If not, and you're trying to do something else, you might need to clarify a bit more.
Upvotes: 2
Reputation: 79830
Try as below,
title: '<img src=../' + provider_img + '/>',
provider_img
is a var and in title you should keep it out of quotes if you want the var to replace the value.
Upvotes: 2