I want to display the following text for the tag. How do I escape the single quotes for the following?
$(\"#spn_err\").text($(\'#tx
It is close. Use the .val() method:
$('#spn_err').text($('#txt1').val() + ' is not valid');
$("#spn_err").text("'" + $('#txt1').attr('value') + "' is not valid");
Like this:
$("#spn_err").text("'" + $('#txt1').val() + "' is not valid");
Inside double quotes, single quotes are normal characters and vice versa. Otherwise you can escape them by prepending a backslash: "\""
or '\''
.
$("#spn_err").text('\'' + $("#txt1").attr("value") + '\' is not valid');