Reputation: 1435
I'm trying to add textarea dynamically inside a div using JQuery & have following code:
@{
string emailText = ViewBag.email as string;
}
<script type="text/javascript">
$(document).ready(function () {
var textArea = $('<textarea style="padding-left:100px" />');
emailText = emailText.replace("$[Group Custom Text]$", textArea);
$("#divConfirmation").append(emailText);
});
</script>
<div id="divAppointmentConfirmation"></div>
Problem is I get string value "[object Object]" instead of HTML control (textarea).
Upvotes: 2
Views: 4069
Reputation: 1
check the following sentences:
$("#divConfirmation").append(emailText);
<div id="divAppointmentConfirmation"></div>
you can trivially observed that divConfirmation isn't divAppointmentConfirmation correct it too.
Upvotes: 0
Reputation: 113355
Yes, because textArea
is a jQuery object.
And ({}).toString()
is "[object Object]"
.
Use outerHTML
to get its html.
emailText = emailText.replace("$[Group Custom Text]$", textArea[0].outerHTML);
Upvotes: 3
Reputation: 33870
That's because it need a string as parameter. You can try this:
emailText.replace("$[Group Custom Text]$", textArea[0].outerHTML);
Upvotes: 1