menus.getTargetElement()

Draft
This page is not complete.

Returns the element for a given targetElementId

Only works in the document where the right clicked element is in, so everywhere but in the background page.

Syntax

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

Parameters

targetElementId
The property of the menus.OnClickData object passed to the menus.onClicked handler or menus.onShown event.

Return value

The element referred to by the targetElementId parameter. If the targetElementId parameter is not valid, the method returns null.

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
Basic supportChrome No support NoEdge No support NoFirefox Full support 63Opera No support NoFirefox Android No support No

Legend

Full support  
Full support
No support  
No support

See also

Document Tags and Contributors

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