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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:05:47+00:00 2026-05-25T12:05:47+00:00

I am having a problem getting TinyMCE to wrap the contents of the selection.

  • 0

I am having a problem getting TinyMCE to wrap the contents of the selection.

The first style_format simple adds the class to the selected element, this works fine.

The problem is with the second style_format I want it to wrap the selected elements inside of the

E.g.
BEFORE

<p>test text</p>
<p>test text</p>
<p>test text</p>
<p>test text</p>

AFTER

<p class="accordion_top">test text</p>
<div class="accordion_middle">
<div class="accordion_middle-wrapper">
    <p>test text</p>
    <p>test text</p>
    <p>test text</p>
</div>
</div>

Using the jQuery version I have below, the code in question is the bottom style formats

$("#tinymce").tinymce({
    script_url : HOME+"/webapp/shared/javascript/tiny_mce/tiny_mce.js",
    mode : "textareas",
    theme : "advanced",
    skin : "cirkuit",
    width: "726",
    plugins : "advlist,insertdatetime,paste,print,searchreplace,spellchecker,table,wordcount,visualchars,xhtmlxtras,template,codemagic",
    theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,selectall,undo,redo,|,hr,acronym,charmap,blockquote,replace,|,insertdate,inserttime,|,cleanup,removeformat,codemagic,",
    theme_advanced_buttons2 : "wrap_div,styleselect,formatselect,|,bold,italic,underline,bullist,numlist,|,table,|,link,unlink,insertimage,spellchecker|mybutton",
    theme_advanced_buttons3 : "",
    theme_advanced_buttons4 : "",
    //theme_advanced_buttons1 : "|,,table,pasteword",
    theme_advanced_blockformats : "p,h2,h3,h4,h5,h6",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    forced_root_block : "p",
    force_br_newlines : false,
    force_p_newlines : true,
    valid_elements : "span[class|id],br[class|id],a[href|target|title],img[src|id|width|height|class|alt],i,"+
    "li[class|id],ul[class|id],ol[class|id],p[class|id],"+
    "table[class|id],th[class|id],tr[class|id],td[class|id],thead,tbody,"+
    "h1[class|id],h2[class|id],h3[class|id],h4[class|id],h5[class|id],h6[class|id],strong[class|id],"+
    "div[class|id]",
    content_css : TEMPLATE_HOME+"/css/tinymce.css?" + new Date().getTime(),
    plugin_insertdate_dateFormat : "%d/%m/%Y",
    plugin_insertdate_timeFormat : "%H:%M",
    paste_auto_cleanup_on_paste : true,
    convert_urls: false,
    relative_urls: false,
    // Style formats
    style_formats : [
         {title : 'Accorion Top', selector : 'p,h2,h3,h4,h5,h6', classes : 'accordion_top'},
         {title : 'Accorion Middle', block : 'div', classes : 'accordion_middle'}
    ],
    setup: function (ed) {
        // Create an wrap DIV button
        ed.addButton ('wrap_div', {
            'title' : 'Wrap Accordion',
            'image' : HOME+'/webapp/shared/javascript/tiny_mce/themes/advanced/img/createlink.gif',
            'onclick' : function () {
                var text = ed.selection.getContent({ 'format' : 'text' });
                if (text) {
                    tinyInsert('<div class="accordion_middle"><div class="accordion_middle-wrapper">' + text + '</div></div>');
                }
            }
        });
    }
});
  • 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-25T12:05:47+00:00Added an answer on May 25, 2026 at 12:05 pm

    It requires big changes in the tinymce core (Formatter.js) to get what you want using the style plugin.
    I would write an own function placed in an own tinymce plugin.
    To achieve your goal you wouldn’tneed that much code.

    EDIT: You got it almost correct. Try this first using spans to make sure this works in your editor.

    setup: function (ed) {
        // Create an wrap DIV button
        ed.addButton ('wrap_div', {
            'title' : 'Wrap Accordion',
            'image' : HOME+'/webapp/shared/javascript/tiny_mce/themes/advanced/img/createlink.gif',
            'onclick' : function () {
                var text = ed.selection.getContent({ 'format' : 'text' });
                if (text && text.length > 0) {
                    ed.execCommand('mceInsertContent', false, '<span class="accordion_middle"><span class="accordion_middle-wrapper">' + text + '</span></span>');
                }
            }
        });
    }
    

    Next step will be to replace the spans withs divs and make sure your tinymce settings will allow nested div tags (see the valid_children setting).

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

Sidebar

Related Questions

I'm having a problem getting a simple ASP.NET webpage to display. The page contains
I'm having a problem getting more memory out of PHP. This is the error
I'm having a problem getting this type conversion working correctly. My guess is the
I'm having a problem getting the root URL with this PHP function I composed.
I'm having a problem getting this functionality to work. Situation is: User Drags an
Having a problem getting the URL for a resource for some reason: This code
I'm pretty new to NHibernate and am having a problem getting this kind of
I am having problem getting my tooltip to work when using the jQuery load()
Having a problem getting a TreeView control to display node images. The code below
I am having a problem getting a list of fields from a query defined

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.