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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:56:27+00:00 2026-06-14T01:56:27+00:00

I have a project in which a content editable div is parent then using

  • 0

I have a project in which a content editable div is parent then using jQuery I wish to add p tags inside this div. Which can then also be edited. Almost like a mini note pad document.

The problem I have is that i’m using the jQuery .append function on the parent div which adds the p class to the end of the div. What I need it to do is add the p class after the current selected p / the p the caret cursor is currently inside.

jQuery I am currently using –

  $(".addHeading").click(function() {
     $('.textArea').append('<div class="heading">Heading</div>');
  });

  $(".addParagraph").click(function() {
     $('.textArea').append('<div class="paragraph">Test</div>');
  });​

I have put my current code into a JSFiddle. I hope it’s obvious what i’m trying to do.

Any help would be greatly appreciated!

JS Fiddle –
http://jsfiddle.net/eheHS/

Regards

  • 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-14T01:56:28+00:00Added an answer on June 14, 2026 at 1:56 am

    By adding a click handler to your newly created paragraph divs, you can save away the last one that was edited. Here’s one solution, but not very elegant (jsFiddle):

    var $lastCaretDiv;
    
    $(".addParagraph").click(function() {
        if ($lastCaretDiv) {
            $lastCaretDiv.after($('<div/>', {
                'html': 'Test',
                'class': 'paragraph'           
            }).click(function () {
                $lastCaretDiv = $(this);
            }));
        } else {
            $('.textArea').append($('<div/>', {
                'html': 'Test',
                'class': 'paragraph'           
            }).click(function () {
                $lastCaretDiv = $(this);
            }));
        }
    });
    

    This will set $lastCaretDiv to the last one that was clicked. If it is defined, then add the new paragraph after it, otherwise append it to the text area.

    My solution has a lot of pitfalls as it is right now, but you have something to work after. I would suggest clearing $lastCaretDiv whenever something else in the text area is clicked, e.g. a header. It all depends on how you want it to behave.

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

Sidebar

Related Questions

I have a class library project which contains some content files configured with the
I have another project which contains static content (css, images, JS, etc.), and I
I have a project which using a a REST API. Here when Isend a
  I am developing a project which is built in CakePHP and using jQuery in
I have a project which is using umbraco cms, ie. MSSQL (Now we are
I am starting a new project which requires content managment and have decided to
I am totaly new to JQUERY and i have got a project in which
Hi I have a project which related to the content based image retrieval. I
I have this project i'm working on and id like to add a really
I have a project in which we are using phpdocx pro to generate 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.