DAK
DAK

Reputation: 1435

JQuery add textarea inside a div

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

Answers (3)

user3814828
user3814828

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

Ionică Bizău
Ionică Bizău

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

Karl-Andr&#233; Gagnon
Karl-Andr&#233; Gagnon

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

Related Questions