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 4539474
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:57:05+00:00 2026-05-21T14:57:05+00:00

I have a <div contenteditable=true> that I am trying to use to get text

  • 0

I have a <div contenteditable="true> that I am trying to use to get text from users. I would use a simple <textarea>, but I need line-breaks and eventually lists and tables etc. I am trying to build something that is semi a rich-text editor, but not a full fledged one. I do not want to use a rich text editor.

I am trying to eliminate the attributes on <span> tags from the text that is typed into the <div contenteditable="true> . Is there a way to do that with Regexp? I was having difficulties coming up with a Regexp because I can’t figure out how to make it so that the string starts with <span and ends with > and any number of characters can be in between. Is there a way to combine that in one Regexp? I came up with /^<span >$/ but that does not work because there is no division between the two strings. Would something like this work: /^[<span][>]$/g?

  • 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-21T14:57:06+00:00Added an answer on May 21, 2026 at 2:57 pm

    Use DOM functions for it. Here’s some code using jQuery to make it easier and nicer to read:

    $('#your-div span').each(function() {
        var elem = this, $elem = $(this);
        $.each(elem.attributes, function(i, attr) {
            if(attr) {
                $elem.removeAttr(attr.name);
            }
        });
    });
    

    Demo: http://jsfiddle.net/ThiefMaster/qfsAb/

    However, in your case you might want to remove attributes not only from spans but from all elements unless the attribute is e.g. align or href.

    So, here’s some JS for that: http://jsfiddle.net/ThiefMaster/qfsAb/1/

    $('#your-div').children().each(function() {
        var elem = this, $elem = $(this);
        $.each(elem.attributes, function(i, attr) {
            if(attr && attr.name != 'href' && attr.name != 'align') {
                $elem.removeAttr(attr.name);
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a simple <div contenteditable=true> working, but, here's my problem. Currently, the
I have a <div> that has contentEditable=true . When I copy-paste content within the
I have a contenteditable div that I want users to be able to select
So I have a contenteditable=true div, of which there are images and text within
I have a contentEditable div with following text for example: <div contentEditable='true'> This document
have this html: <div id=editable contentEditable=true > <span contentEditable=false >Text to delete</span> </div> need
I'm building a simple text editor by setting contentEditable=true on a div (anyway i
I have a contenteditable div where I need to insert text at the caret
I have a CONTENTEDITABLE div and inside that div I have a CONTENTEDITABLE span,
I have a div element with contenteditable set to true, and I want to

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.