javascript - How can I escape backslash while adding html markup using Jquery appentTo function - Stack Overflow

admin2025-03-20  5

On the click of a button I am dynamically adding the following Div to my web page.

The problem is the image source cannot be found due to the incorrect path caused by the backslash just before "\Content". The backslash is already reserved to escape quotes.

How can I workaround this.

$("<div class=\"input-append\"><label style=\"background-color:#e0ffff\">" + artistVal + "</label><img onclick=\"RemoveArtist()\" id=\"removeartist\" src=\"\Content\bootstrap\img\cross-button.png\" /></div>").appendTo(addDiv);

I am getting an error 400 pulling the image added to the div

Request URL:http://myhost:53159/Content%08ootstrapimgcross-button.png

On the click of a button I am dynamically adding the following Div to my web page.

The problem is the image source cannot be found due to the incorrect path caused by the backslash just before "\Content". The backslash is already reserved to escape quotes.

How can I workaround this.

$("<div class=\"input-append\"><label style=\"background-color:#e0ffff\">" + artistVal + "</label><img onclick=\"RemoveArtist()\" id=\"removeartist\" src=\"\Content\bootstrap\img\cross-button.png\" /></div>").appendTo(addDiv);

I am getting an error 400 pulling the image added to the div

Request URL:http://myhost:53159/Content%08ootstrapimgcross-button.png
Share Improve this question edited Nov 21, 2013 at 15:04 BenMorel 36.7k51 gold badges205 silver badges336 bronze badges asked Sep 1, 2013 at 21:12 MilligranMilligran 3,1719 gold badges46 silver badges57 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You can either use double backslashes (\\) in file paths, or use forward slashes (/). Using a forward slash is more reliable, since backslashes don't work correctly on all web servers.

Use slash instead of backslash for your src element. This way you avoid the escaping problem inside URLs

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1742416135a212671.html

最新回复(0)