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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:51:18+00:00 2026-05-13T13:51:18+00:00

So I have a TinyMCE form on my page and it is pre-filled with

  • 0

So I have a TinyMCE form on my page and it is pre-filled with “sections” (divs with specific class names).

I have a couple of plugins that will add to TinyMCE with more “sections”.

I need it so when I push the plugin button it will test to make sure the cursor is not inside a “section” and paste a “section” inside another “section”.

Not sure the direction I need to take to accomplish this. Any help would be great.

more info:
So below is an example of a plugin that adds a button that just inserts a simple dov into the editor at the selection/cursor.

ed.addButton('pluginbutton', {
    title : 'MyPlugin',
    image : 'img/test.png',
    onclick : function() {
        ed.selection.setContent('<div>test</div>');
    }
});

I am currently thinking that onBeforeSetContent is the API event handler I need to set to process whether or not I am in another section and if so send a message to the screen. If not just do the setContent method. I am not sure exactly how to set that up though so I am still figuring that out. Any help here?

  • 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-13T13:51:19+00:00Added an answer on May 13, 2026 at 1:51 pm

    Since it seems like you have control over the plugin, here is how I would edit it to work.

    Note: I am using the jQuery method closest. I figured since you are on the jQuery core team, you are probably using it for this project. If not, just refactor that line as needed. The important part is that selection.getNode() returns the DOM element that is the parent of both the start and end selection points.:

    ed.addButton('pluginbutton', {
        title : 'MyPlugin',
        image : 'img/test.png',
        onclick : function() {
            if( !$(ed.selection.getNode()).closest('div.section').length ){
                ed.selection.setContent('<div class="section">test</div>'); 
            }
        }
    });
    

    Additional thoughts

    Also, to make your plugin aware enough so it won’t put a div as the child of a p tag, you could do something like this:

    Replace onclick above with this:

    onclick: function(){
        var $node = $(ed.selection.getNode());
        if( !$node.closest('div.section').length ){
           // Get highest element that is a direct child of the `body` tag:
           var $parent = $node.closest('body > *');
           // Wrap with our special section div
           if($parent.length) $parent.wrap('<div class="section"></div>');
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with TinyMCE editor. I have form with few text fields and
I have installed VS2010 and MVC2 and testing a simple form using tinyMCE. When
I have a Django form using textareas and TinyMCE for text entry. I would
i have been trying very hard to make tinyMCE work on my page. even
i am using tinymce editor for my form. i have three instance of tiny
I have a problem on submitting an asp.net mvc form that is using Xval
I have a page where I am using accordion and tinymce together. For each
I have set up a form using TinyMCE in my MVC website. To do
I have a data-source connected to a stored proc that will return the one
I have 3 tinymce textarea, in my page. And I want to populate these

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.