is it possible to add a div inside input text area using react

0 votes
Can you tell me is it possible to add a div inside input text area using react
3 days ago in Node-js by Ashutosh
• 23,230 points
23 views

1 answer to this question.

0 votes

Adding a Div Inside a Text Input in React

No, you cannot directly insert a <div> or any other HTML element inside an <input> or <textarea> in React (or standard HTML) because:

Input elements are void elements - They can't contain children in the HTML specification

Textarea only accepts text - The <textarea> element is designed solely for plain text content

Alternative Solutions

1. ContentEditable Div function RichTextInput() {

  const [content, setContent] = useState('');

  return (

    <div 

      contentEditable 

      dangerouslySetInnerHTML={{ __html: content }}

      onInput={(e) => setContent(e.currentTarget.innerHTML)}

      style={{

        border: '1px solid #ccc',

        padding: '8px',

        minHeight: '100px'

      }}

    />

  );

}

answered 3 days ago by Navya

Related Questions In Node-js

0 votes
1 answer

Is it possible to handle React events using the Chrome extension?

Yes, it's possible to handle React events ...READ MORE

answered Feb 22 in Node-js by Kavya
57 views
0 votes
0 answers
0 votes
1 answer
0 votes
0 answers
0 votes
0 answers

How to monitor progress of HTTP Get Request

With the help of code can you ...READ MORE

3 days ago in Node-js by Ashutosh
• 23,230 points
18 views
0 votes
0 answers

How to call another HTTP request after forkJoin is completed (RxJS)?

With the help of proper programming can ...READ MORE

3 days ago in Node-js by Ashutosh
• 23,230 points
16 views
0 votes
0 answers

How to monitor progress of HTTP Get Request

Can you tell me How to monitor ...READ MORE

3 days ago in Node-js by Ashutosh
• 23,230 points
17 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP