0

I'm building a custom Elementor extension and need to access the attributes (settings/controls) of the currently selected widget in the Elementor editor using JavaScript.

So far, I’ve tried inspecting panelView and various parts of the elementor JS namespace. However, I can't seem to get a reliable reference to the currently active widget instance (the widgetModel) in order to call getSetting() or inspect its data.

There can be multiple widgets of the same type on the page, so I need the specific instance that is currently being edited.

I’ve tried using jQuery to find elements with data-setting or tracing the view stack, but nothing solid so far.

How can I get the currently active widget's model (widgetModel) in Elementor editor so I can inspect or manipulate its settings?

1 Answer 1

0
const panelView = elementor?.getPanelView();
const currentPageView = panelView?.currentPageView;

if (panelView && currentPageView?.model && currentPageView?.model?.attributes?.widgetType) {
    const widgetModel = currentPageView.model;
                   
    // Getter
    widgetModel.getSetting(key);
    
    // Setter
    widgetModel.setSetting(key, value);
}

// Found another hook too for new version of Elementor.
// Fires when a widget gets active.

elementor.hooks.addAction('panel/open_editor/widget', (panel, model) => {
    // Your code here.
}
Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.