0

I'm trying to change my HTML code by using JQuery. When I use this code it works:

$('.theclass').html('hello');

But what I really want to do is to include a statemente in my HTML. So I tried this but it does not work.

$('.theclass').html( 
    "<select name='myName' id='myId'>
        <option value=''>-</option>
        <option value='A'>A</option>
        <option value='B'>B</option>
    </select>"
);

Any help? Thanks

borjacastillo
  • 269
  • 1
  • 2
  • 7

3 Answers3

4

Try to concatenate the strings properly when your string input exceeds out to a newer line,

$('.typehidden .controls').html( 
    "<select name='myName' id='myId'>"
        + "<option value=''>-</option>"
        + "<option value='A'>A</option>"
        + "<option value='B'>B</option>"
    + "</select>"
);
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
2

You can use \ to create multline string.

$('.theclass').html( 
    "<select name='myName' id='myId'>\
        <option value=''>-</option>\
        <option value='A'>A</option>\
        <option value='B'>B</option>\
    </select>"
);
Satpal
  • 132,252
  • 13
  • 159
  • 168
1

multi line without + or \ operator doesn't work , use either Rajaprabhu answer or you can write in a single line.

$('.theclass').html(  "<select name='myName' id='myId'><option value=''>-</option><option value='A'>A</option><option value='B'>B</option></select>");
Govind Singh
  • 15,282
  • 14
  • 72
  • 106