String literal in object string literature

I am trying to put some html inscription inside an array for later search. My editor produces a syntax error in the description line1, I can not understand why. Any help is appreciated. The code is below. Thanks a

var modalcontent = { description1 : '<div id = "description"><div class = "tbc"> <label class = "tbc" for = "tbc">Description</label> </div> <div class = "tbc"> <input type = "text" class = "tbc" name = "description" id = "tbc" placeholder = "Enter description"> </div> </div> <!--end description div-->' } 
+4
source share
1 answer

You have an open string literal. JavaScript strings are not multiline by default.

 var modalcontent = { description1 : '<div id = "description"><div class = "tbc"> '+ '<label class = "tbc" for = "tbc">Description</label>'+ '</div>'+ '<div class = "tbc">'+ '<input type = "text" class = "tbc" name = "description" id = "tbc" placeholder = "Enter description">'+ '</div>'+ '</div>'+ '<!--end description div-->' } 

(violin)

Alternatively, you can create a multi-line string using the \ character, which only work in new implementations. See this related question or language specification .

Note. This is usually not the best idea to store HTML in lines, which makes it difficult to debug and work. You can usually use patterns. It is not that there are no good use cases; it rarely happens.

+5
source

Source: https://habr.com/ru/post/1487614/


All Articles