-5

I have a JavaScript in which one of the line is

imgtag = '<div style="float:left; padding:0px 10px 5px 0px;"><a expr:href="data:post.url"><img src="'+img[0].src+'" width="218px" height="170px"/></a></div>';

In the above code I want <a expr:href="data:post.url"> to be changed in <a expr:href='data:post.url'> but adding this type of closing tag is conflicting with the Javascripts closing tag. What should I do ?

Dhiraj Barnwal
  • 180
  • 2
  • 15
  • 2
    there is no difference between `'`and `"` – Praveen Aug 09 '13 at 15:04
  • if you just want to change the type of quote, try escaping: `\'` – Harry Aug 09 '13 at 15:04
  • 1
    Please [learn about strings in JavaScript](http://stackoverflow.com/questions/242813/when-to-use-double-or-single-quotes-in-javascript), and read [this](http://www.quirksmode.org/js/strings.html#link2) too – Bojangles Aug 09 '13 at 15:04
  • 4
    They're not "closing tags", they're string delimiters. – JJJ Aug 09 '13 at 15:05

3 Answers3

2

You can escape the single quote like \'

Raidri
  • 17,258
  • 9
  • 62
  • 65
2

Do you mean you want to escape the characters?

If so you will need to include \' instead of ", and change your code to:

imgtag = '<div style="float:left; padding:0px 10px 5px 0px;"><a expr:href=\'data:post.url\'><img src="'+img[0].src+'" width="218px" height="170px"/></a></div>';

This will result in the line expr:href='data:post.url'

Tim B James
  • 20,084
  • 4
  • 73
  • 103
1

Escape it with \'.

imgtag = '<div style="float:left; padding:0px 10px 5px 0px;"><a expr:href=\'data:post.url\'><img src="'+img[0].src+'" width="218px" height="170px"/></a></div>';

sushain97
  • 2,752
  • 1
  • 25
  • 36