score:6
Add a click listener to document and try to check if it is clicked inside of your container element or outside. If clicked inside, the closest method will return parent container (it will give you the container element), else if clicked out side it will give null. We are interested in null (clicked outside) then we will hide the context menu div
document.addEventListener('click', function(e){
let inside = (e.target.closest('#container'));
if(!inside){
let contextMenu = document.getElementById('contextMenuId');
contextMenu.setAttribute('style', 'display:none');
}
});
If you need to set a boundary other than this, just replace #container
with anything suitable.
Few browsers don't yet support closest if you are not using jQuery make sure you use the pollyfill for function closest https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
Updated fiddle https://jsfiddle.net/28tvp30b/
NOTE: your container element is almost taking up the whole page its tough to click outside of container. Check if you are actually clicking outside container element.
Source: stackoverflow.com
Related Query
- How to hide the context menu on clicking outside uisng JS?
- How do I align the hover/dropdown menu with the my custom context button symbol?
- How do I hide the code for the chart data in highcharts?
- How to hide labels in the highcharts in the pie
- How to export a Highchart chart to PDF thanks to a button outside the chart?
- How can i hide all the Series in highcharts at a time
- Highcharts - how to remove "Open in Highcharts Cloud" from the export menu
- How to hide series via the legend in highstock ?
- HighCharts Hide specific context Menu items
- How can I hide ALL series with the same ID with a button on highcharts? (line graph)
- How do I hide a Highcharts series from the chart, but always show it in the tooltip?
- How Can I Hide a Pie Chart's Slice in HighCharts Without Removing It From the Legend?
- Highcharts context menu button appearing thrice for the same chart
- how to display 2 same highcharts without duplicate the code
- How can we add chart context menu in highcharts-angular?
- How to hide only the columns of this group when hovering over a group column in highcharts?
- How to avoid bad behavior zooming to areas outside the data range
- How do I completely hide the chart title in a HighCharts chart?
- How to call Highcharts tooltip formatter function from outside the config object?
- Strange character in the Highstock source code
- Highcharts: How to make curve start outside of the visible view horizontally?
- How to hide other series when clicking on legend on highcarts?
- "viewFullscreen" menu item is not showing in the context menu of highcharts 6.2.0
- How can hide the icon legend
- How to make a HighCharts drilldown column/bar chart that does not hide the non-drilldown categories
- How to hide the export button in highcharts-ng
- How to Hide rest of the region when user clicks pie chart?
- How to show only the last 100 candlesticks or hide the first 50 candlesticks in Highcharts Stock Chart?
- How to hide the figures on the coordinates in a High Chart graph?
- How to hide stackLabel in highcharts when it is bigger than the column
More Query from same tag
- Highcharts doesn't work
- Highstock Chart - setExtremes event data missing
- Highcharts - how to do a responsive pie chart when the texts of the labels are long
- Highcharts export menu does not show up fully
- Multiple labels in Highcharts Pie Graph
- High Charts stack column from json object
- Dynamically Transform Data with User Input (Highcharts, JavaScript,Django)
- How to allow the country labels to auto-hide when using HTML?
- Highstock set XAxis extreme without data
- Highstock Candlestick connect nulls or zero's
- Dyanamic highchart with csv/txt input file
- Not able to disable legend title / enable legend title as required while expoting Highcharts
- HighCharts Date format
- HighCharts: Getting rid of tooltip but mantain crosshairs
- Highcharts with ajax/ json and SQL Server ASP.NET
- Create background quadrants in scatterplot
- HighCharts : Remove auto margin for errorBar
- How can I specify the position of the columns relative to the X-axis labels in a column chart using Highcharts?
- Highcharts Circular Percentage Chart
- Highcharts : Export multiple charts to pdf in custom layout
- Set the values of heatmap in highCharts in javascript function
- Highcharts: How to group column chart on category
- Highcharts don't render in Internet Explorer 11
- align text on the left and the right in Highcharts
- Toggle flags on/off with a button in highcharts/highstock
- Issues in Data Label
- JavaScript PHP HighChart transform a PHP array to a javascript array
- Make datepicker work with highcharts
- Highchart: xAxis Label text not displayed when plotting 2 points
- Highcharts Tooltip cropping