user3386779
user3386779

Reputation: 7175

regular expression mismatch in html

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

Upvotes: 0

Views: 52

Answers (2)

Harald Gliebe
Harald Gliebe

Reputation: 7544

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

Upvotes: 1

Soviut
Soviut

Reputation: 91515

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

Upvotes: 0

Related Questions