Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  59] [ 4]  / answers: 1 / hits: 55640  / 14 Years ago, fri, june 25, 2010, 12:00:00
$(#addSelect).click(function() {
$(#optionsForm).after(Hello world.);
} );


This works.



$(#addSelect).click(function() {
$(#optionsForm).after(<tr>
<td><input type=text class=optionField value=Options /></td>
<td>
<ul class=option>
<li><select><option>Value..</option></select></li>
</ul>
</td>
</tr>);
} );


Something like this doesn't.



In Chrome, I get the error Unexpected token ILLEGAL. After Googling I've discovered my teeny brain doesn't know much about javascript and multi-lines. So I added '' to then end of each line. Yet, I now get the error Unexpected identifier.



I'd like this to not be as difficult as I'm making it :)


More From » jquery

 Answers
22

Use back ticks ` to start and finish the string



$(#addSelect).click(function() {
$(#optionsForm).after(`<tr>
<td><input type=text class=optionField value=Options /></td>
<td>
<ul class=option>
<li><select><option>Value..</option></select></li>
</ul>
</td>
</tr>`);
} );




[#96414] Sunday, June 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradley

Total Points: 555
Total Questions: 102
Total Answers: 99

Location: Tajikistan
Member since Fri, Nov 27, 2020
4 Years ago
;