简体   繁体   中英

Invalid or unexpected token when a div is appended jquery

I want to append a div(dynamically created) inside a div. I get this error when i append a div. But if i try to append a string it works without any issue. I dont understand the reason behind this. I don't see anything wrong with my syntax as well. The below one cause error

$("#scheduled_bar_panel_col").append(
 "<div class='col-lg-3 col-md-4 col-sm-6 col-xs-8' id = 'panel_column'>
 </div>"
); 

But this works perfect

$("#scheduled_bar_panel_col").append(
"Hello"
);

Let me know what is the reason behind this and how to solve this

Because "" doesn't support multi lines. Use `` for them if you use modern JavaScript ES6 Browser compatibility

`<div class='col-lg-3 col-md-4 col-sm-6 col-xs-8' id = 'panel_column'>
 </div>`

Or use to separates strings and concatenate them.

"<div class='col-lg-3 col-md-4 col-sm-6 col-xs-8' id = 'panel_column'>" +
"</div>"

You need to use + symbol at the end of line:

$("#scheduled_bar_panel_col").append(
  "<div class='col-lg-3 col-md-4 col-sm-6 col-xs-8' id = 'panel_column'>" +
  "</div>"
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM