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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:11:03+00:00 2026-06-06T19:11:03+00:00

Ok. I have an editable div into which I can enter some text. However

  • 0

Ok. I have an editable div into which I can enter some text. However after entering I have 3 buttons: black, yellow and green.

What I want to be ble to do is to then click ie button “black” and then click each of the word which I have typed into the editable area. After clicking a word, that clicked word should have a div class=’black’ wrapped around it?

Also if the same word is clicked again I need to remove the wrapped div (so I can chamge the colour of the word,if I whish to do so?).

Furthermore I want the div to be deleted if I delete any words wrapped with a div.

Any help is appreciated?

Thanks in advance.

  • 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-06-06T19:11:04+00:00Added an answer on June 6, 2026 at 7:11 pm

    Are you using jQuery? You need something like that:

    function prepareDivContainer()
    {
      // remove extra spaces
      var str = $("#editableDiv").text().replace(/[\s]+/g, ' ');
    
      // split the string by space into words
      var words = str.split(' ');
    
      // clear the content of the editable div
      $("#editableDiv").text('');
    
      // insert each word wrapped with a div
      for (var i = 0; i < words.length; i++)
      {
        $("#editableDiv").append('<div id="word'+i+'">'+words[i]+'</div>');
      }
    }
    

    This function you call after the user has finished inserting text into the div. It will wrap all word into div.

    So, now you can made these divs (words) clickable by binding to the click-event:

    $(document).ready(function () {
      $("#editableDiv div").live("click", function(){
        // do something with the clicked word (div), e.g. add or remove css classes
        // look here: http://api.jquery.com/category/css/
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a helper called EditableArea which provides a user with a runtime-editable div
I have a content editable div. Within this I am inserting a <pre>some code</pre>
I have a problem with this function: $(#contentdiv).click(function() { $(this).append(<div class='editable'>For some reason this
I have a div containing some content, in which there are some links. The
have this html: <div id=editable contentEditable=true > <span contentEditable=false >Text to delete</span> </div> need
I have some elements that need to have the text inside editable, for this
I have a editable div: <div id=artikel contenteditable=true></div> It works nice, I can edit
I have an editable iframe with some textnodes. During editing i want (on some
I have a form in which I have an editable authors field. When I
I have a datagrid view which is editable. I'm getting the value of a

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.