Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7589601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:12:06+00:00 2026-05-30T20:12:06+00:00

I have a text input that I’d like to replace with a textarea, preserving

  • 0

I have a text input that I’d like to replace with a textarea, preserving all of the attributes. How can I do this with jQuery?

Sample input:

<input type="text" name="newfeature" id="newfeature"
  class="form-required" tabindex="3"
  aria-required="true" />

Desired output:

<textarea type="text" name="newfeature" id="newfeature"
  class="form-required" tabindex="3"
  aria-required="true"></textarea>

I know this can be done manually using the .prop() selector and specifying each attribute/property, but how can I do it dynamically?

Also, this is not necessary, but would it possible to preserve the bindings when doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:12:07+00:00Added an answer on May 30, 2026 at 8:12 pm

    This also works with the value attribute correctly:

    $('input').each(function() {
    
        var attrs = {};        
    
        $.each(this.attributes, function() {
           attrs[this.name] = this.value;
        });
    
        $(this).replaceWith($('<textarea>').prop(attrs));
    });​
    

    Example: http://jsfiddle.net/FyYDT/

    ADDED

    If you want jQuery events to pass along (not recommended), you need to re-bind them. Something like:

    $('input').click(function() {
    
        alert('hey');
    
    }).each(function() {
    
        var attrs = {},
            ta = $('<textarea>');
    
        $.each(this.attributes, function() {
           attrs[this.name] = this.value;
        });
    
        $.each($(this).data('events'), function(i, f) {
            $.each(f, function(){
                ta.bind(i, this.handler);
            });
        });
    
        $(this).replaceWith(ta.prop(attrs));
    
    });​
    

    http://jsfiddle.net/FyYDT/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have input text that contains a ' like in this text Frank's Reel
I have a jQuery jPicker colorpicker that is bound to an input text field
I have a text input field that has some sample text in a light
I want to have a text input that on focus selects all of the
I have a single text area input that I would like to get as
I have a text input area defined like this: <TextBox> <TextBox.Text> <Binding Path=MyProperty> <Binding.ValidationRules>
I have input text that can be long HTML text with tags and so
I need to be able to take an arbitrary text input that may have
I have a paragraph of text below that I want to use an input
I have one text input and one button (see below). How can I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.