0

This is my textarea :

<div>@Html.TextAreaFor(m => m.Article.ArticleContent, new { @class = "my_textarea", id = "textareaInput" })

and script :

<script type="text/javascript">
    $(document).ready(function () {
        $('#textareaInput').click(function () {
            var htmlStr = $('#textareaInput').val();
            $('#textareaInput').val($('<div/>').text(htmlStr).html());
        });
    });
</script>

when I write <p>some code</p> output is : &lt;p&gt;some code&lt;/p&gt; . But I expect : some code.

How may I do this? Thanks.

1 Answer 1

1

If your intention is to clear the tags, then try $('<div/>').html(htmlStr).text():

    $(document).ready(function () {

        $('#textareaInput').change(function () {

            var htmlStr = $('#textareaInput').val();
            $('#textareaInput').val( $.trim( $('<div/>').html(htmlStr).text() ) );

        });
    });
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.