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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:30:31+00:00 2026-06-08T11:30:31+00:00

I need to add CSS classes to basically any element that the user selects

  • 0

I need to add CSS classes to basically any element that the user selects or points to in CKEditor. For example if there is a table that contains an list, my element structure and elementspath might look like this under the cursor:

body > table > tbody > tr > td > ul > li

Out of those, the user needs to be able to somehow select or point to the table, tr, td, ul or li element. After the user selected / pointed to the element they want to add a class to they would get a dialog to choose a class.

How would I detect which element the user wants to point to?

I’m open to any and all suggestions, even if that means hacking the core. For example I would think that this is doable with elementspath having a context menu where I could click something like “properties” for the element and that would bring up a dialog where the user could choose a class, but I have no idea how or even if it is possible to add a context menu to elementspath!

In Firefox this kind of works out of the box in that when a user clicks an element in elementspath I can GetSelectedElement and it returns what the user has clicked, but it doesn’t work in IE/Chrome.

  • 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-08T11:30:32+00:00Added an answer on June 8, 2026 at 11:30 am

    I kind hacked together a horrible but somewhat functional solution. In elementspath plugin.js I added

    function onContextMenu(elementIndex, ev) {
        editor.focus();
        var element = editor._.elementsPath.list[elementIndex];
        editor.execCommand('elementspathContextmenuForElement', ev, element);
    }
    var onContextMenuHanlder = CKEDITOR.tools.addFunction(onContextMenu);
    

    And then where the elementspath item html is generated I added:

    oncontextmenu="return CKEDITOR.tools.callFunction(', onContextMenuHanlder, ',', index, ', event );"
    

    And then I made a plugin that creates a html “context menu”

    CKEDITOR.plugins.add('elementspathcontextmenu', {
        init: function (editor) {
            editor.addCommand('elementspathContextmenuForElement', {
                exec: function (editor, event, element) {
                    debug(element);
                    var tempX = event.pageX + 'px';
                    var tempY = event.pageY + 'px';
                    window.newdiv = document.createElement('div');
                    window.newdiv.setAttribute('id', "tmpContextMenuDiv");
                    window.newdiv.style.width = 300 + 'px';
                    window.newdiv.style.height = 300 + 'px';
                    window.newdiv.style.position = "absolute";
                    window.newdiv.style.left = tempX;
                    window.newdiv.style.top = tempY;
                    window.newdiv.innerHTML = '<p><a href="#" onclick="return false;">Do something</a></p>';
                    document.body.appendChild(window.newdiv);
                },
                canUndo: false    // No support for undo/redo
            });
        }
    });
    

    I feel a bit dirty hacking the core like that and creating a div element for the context menu in that way but it kind of works for me. This is by no means the final code but it gets the point across.

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

Sidebar

Related Questions

I can't access a element with its href. Like this example, i need add
I've got a tr:table that I need to style using CSS. All the normal
I need to add CSS classes to each item output by an XSLT template.
I need to add css height to each page dynamically with jQuery. So far
I need to add a CSS class to the TR (or multiple TR's) of
need to add a 2nd css stylesheet to a page. do i add a
I need add Auto complete on apex Tabular Form. there is a column as
I need add a new user group for mediawiki. The new group has more
We need to add a javascript element inside an iframe (its inside the same
I'm writing my own CSS for jQuery UI. Basically, I need to have different

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.