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

  • SEARCH
  • Home
  • 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 7645813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:02:34+00:00 2026-05-31T10:02:34+00:00

How to remove all div tags, but not content, which it have? (Working with

  • 0

How to remove all div tags, but not content, which it have? (Working with conteneditable=”true”, HTML5)

I have a not real textarea – just <div> with contenteditable="true". When I’m pressing ‘submit’ button, code is reading innerHTML of this element. It’s not good.

So, I want to use it as textarea, I need to:

  1. Remove <div> tags without content (when I’m starting new line, browser closing previous <div> (if exist) and starting new <div>.
  2. Remove all other tags, different from <br /> (but if <br> tags more than 2 on a row, delete it).

How to realize it? On server side and on user side (because it sends by xhr).

  • 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-31T10:02:35+00:00Added an answer on May 31, 2026 at 10:02 am

    I have used content editable divs in the past, the best way to use them is indirectly;
    rather than having them throw the content at php, have a hidden textarea somewhere, with the submit button in that (the submit not hidden obviously) and then the content editable div elsewhere. You can then use jQuery to grab the content of your div and then use some funky regex to parse it for your <br /> and <div> and </div> tags.

    <div contenteditable="true" style="width:200px; height:100px;" id="InputDiv">
    ...
    </div>
    
    <form action="something.php">
        <textarea id="InputArea" style="visibility:hidden;">
        <input onclick="getData()"type="submit" value="submit" >
    </form>
    

    With the corresponding jQuery:

    function getData(){
        var rawDiv = $("#InputArea").text();
        var parsedStr = /*some funky regex*/;
        $("#InputArea").text(parsedStr);
    }
    

    I seem to have misplaced my previous work with jquery and contenteditable divs, but something along this line should work.

    An alternative:

    Rather than using content editable divs, why not use markdown? There would be less need to sort out this kind of problem.

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

Sidebar

Related Questions

Possible Duplicate: Php: remove all tags, but “a href” in a text Is there
I have the following syntax in which I want to remove all css classes
I have a function which removes all attributes in all tags except a few
How do I remove all attributes which are undefined or null in a JavaScript
How can one remove all text, but leave the structure intact? for example: <animals>
I want to remove all null properties in a generic object. It doesn't have
I'm working on ASP.NET MVC3. I was told by my senior to remove all
I have recently started working with JSF2.0 and Facelets, but have run into what
I have in PHP a string which contain stuff like this: <div>some html</div> <?xml:namespace
I want to remove all styles from tags with PHP. For example. Original: <body

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.