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
  • 64,912
  • 15
  • 96
  • 124
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
  • 129,808
  • 12
  • 152
  • 166
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
  • 14,768
  • 13
  • 67
  • 100