Charles Michel Charles Michel - 6 months ago 10
jQuery Question

html </script> is not placing inside a single quotes

In my program i wanted to append block of html code using js append statement as follows



<script>
$("#day_s_add{{ $row['hdr_id'] }}").click(function () {
$("#day_s{{ $row['hdr_id'] }}").append('<script> $(function() { $( "#datepicker{{ $row["hdr_id"] }}" ).datepicker({ dateFormat : "dd-mm-yy", }); });</script>');
});
</script>





here the
</script>
tag inside single quotes on append statement is not working :( how to make the closing script tag as a normal string.

thanks

Answer

Did you try escaping the closing tag? You also missing closing )};.

Try:

$("#day_s_add{{ $row['hdr_id'] }}").click(function () {
    var str = '<script>$(function() {$( "#datepicker{{ $row["hdr_id"] }}" )' +
    '.datepicker({   dateFormat : "dd-mm-yy",  }); });\</script>';
    $("#day_s{{ $row['hdr_id'] }}").append(str);

});

And please respect peoples which will help you, format your sample!