$("#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 :)
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..
Answer: Use String Concatenation You can use string concatenation (through + operator) to create a multi-line string.
Method 1: Multiline-strings are created by using template literals. The strings are delimited using backticks, unlike normal single/double quotes delimiter.
Template literals are strings delimited by backticks, instead of the normal single/double quote delimiter. They have a unique feature: they allow multiline strings: const multilineString = `A string on multiple lines` const anotherMultilineString = `Hey this is cool a multiline st r i n g ! `
Change all the double quotes for the attributes to single quotes.
$("#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>"); } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With