0

I am adding dynamic tags based on a drop down selection; but .html adds my tags as text not real html; here is my code; am I doing something wrong:

$("#trigger_type").change(function() {

    var my_html = "";
    var trigger = $("#trigger_type").val();

    if (trigger == "hybrid") {
        my_html = my_html + "<div class='form-group'> < label for = 'expires_on'> Expires On </label>< input type = 'text' class = 'form-control' id = 'expires_on' placeholder = 'DD-MM-YYYY'> < input type = 'radio' name = 'expires_never' value = 'never' > Never < br >< /div>";
    }
    $("#my_div").html(my_html);

});

If you need more clarification please let me know!

2
  • Not sure if this is your problem, but you might want to initialize my_html outside of your .change script. Then you don't have to add my_html to my_html unless you're trying to .append html to a certain spot Commented Feb 12, 2014 at 22:59
  • try taking whitespace out of the tags eg < label should be <label Commented Feb 12, 2014 at 23:00

1 Answer 1

3

Remove the spaces after your <s.

< label ...

should be

<label ...

http://jsfiddle.net/bH38G/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.