Stone Stone - 1 month ago 6x
Javascript Question

add white space when create a div when prepend

I use this

$("#containerSeparateChart").prepend("<div class="+ key +"></div>")

to create dynamic
when I click a button depend on the key I create the name of the class, but now I want to add one more class for example

I try this

$("#containerSeparateChart").prepend("<div class="+ key +"col-xs-6"+"></div>")

this add the class but, together like this
and I want a space between the name like this
class="keyname col-xs-6"

I try to use all this option

  • $("#containerSeparateChart").prepend("<div class="+ key +" col-xs-6"+"></div>")

  • $("#containerSeparateChart").prepend("<div class="+ key +"&nbsp;col-xs-6"+"></div>")

  • $("#containerSeparateChart").prepend("<div class="+ key + " "+"col-xs-6"+"></div>")

But all this case create something like this

class="keyname" "col-xs-6"

Any idea what I doing wrong!

thanks in advance!


Just a small issue with your quotes:

$("#containerSeparateChart").prepend('<div class="' + key + ' col-xs-6"></div>');


Side note: If you are not already, I would recommend using a code editor (IDE) such as Atom ( Most modern editors would typically pick up on syntax errors like this.