menus.getTargetElement()

Draft
This page is not complete.

Returns the element for a given targetElementId

Syntax

let elem = browser.menus.getTargetElement(targetElementId);

Parameters

targetElementId
The property of the menus.OnClickData object passed to the menus.onClick handler.

Return value

The element referred to by the targetElementId parameter.

Examples

The following example uses the getTargetElement method to get the element referred to by the info.targetElementId property and then removes it.

browser.menus.create({
  title: "Remove element",
  documentUrlPatterns: ["*://*/*"],
  contexts: ["audio", "editable", "frame", "image", "link", "page", "password", "video"],
  onclick(info, tab) {
    browser.tabs.executeScript(tab.id, {
      frameId: info.frameId,
      code: `browser.menus.getTargetElement(${info.targetElementId}).remove();`,
    });
  },
});

Browser compatibility

No compatibility data found. Please contribute data for "webextensions.api.menus.getTargetElement" (depth: 1) to the MDN compatibility data repository.

See also

Document Tags and Contributors

Contributors to this page: Brettz9, irenesmith, ExE-Boss
Last updated by: Brettz9,