0

I have a block of html code in variable card in js file.I caught regular expression not match in card variable error.All single and double quotes matches.What I did wrong in html block.Is any typo error.

(function ($) {
Drupal.behaviors.one_time_popup = {
attach: function (context, settings) {
var celeType=Drupal.settings.one_time_popup.celeType;
 card="<div class=\'cardTemplate-aniv\'> 
 <p class=\'bir-anniv-wishes\'>Happy Birthday and Successful Anniversary</p>
 <p id=\'aspirian-name\'>"+userName+"</p>
 <img src=\'"+Drupal.settings.publicpath+"/Birthday_Images/birthdayTemplate1.jpg\' style=\'width:250px;height:230px;\'>
 <img src=\'"+Drupal.settings.publicpath+"/Anniversary_Images/"+anniversaryCount+"Anniversary.jpg\' style=\'width:250px;height:250px;\'>
</div>";
 }
};
}(jQuery)); 

I have one more temmplate

 cardTemplate1 = "<div class=\'cardTemplate\'><span class=\'birthdayImage\'></span><p class=\'wishes\'>Happy Birthday <span id=\'aspirian-name\'>"+userName+"</span> !</p><img src=\'"+Drupal.settings.publicpath+"/Birthday_Images/birthdayTemplate1.jpg\'></div>";

which shows regular expression mismatch without escape single quotes

user3386779
  • 6,883
  • 20
  • 66
  • 134

2 Answers2

1

You can't have multiline string literals in double quotes. If you have ES6 you can use backticks to have a multiline template string. See creating-multiline-strings-in-javascript

Harald Gliebe
  • 7,236
  • 3
  • 33
  • 38
0

You don't need to escape the single quotes '.

Soviut
  • 88,194
  • 49
  • 192
  • 260