The menu does not appear when I attempt to right-click on the grid header

  • Is there a way to add a right-click menu to the grid header?
  • The right-click functionality works on Google links, but not on the grid header.
  • Any suggestions on how to resolve this issue?
  • Below is the code I'm using:

http://jsfiddle.net/c7gbh1e9/

$('body').on('contextmenu', 'a.test', function() {


  //alert("contextmenu"+event);
  document.getElementById("rmenu").className = "show";
  document.getElementById("rmenu").style.top = mouseY(event);
  document.getElementById("rmenu").style.left = mouseX(event);

  document.getElementsByClassName("k-grid-header").className = "show";
  document.getElementsByClassName("k-grid-header").style.top = mouseY(event);
  document.getElementsByClassName("k-grid-header").style.left = mouseX(event);

  //getElementsByClassName

  window.event.returnValue = false;


});

Answer №1

The reason for this occurrence is that the event triggers when a.test is right-clicked. To resolve this, modify it to .test and include a test class in the grid header.

Answer №2

The code snippet in the Fiddle is setting a listener on #test, however, the element actually has an id of #test1. This discrepancy needs to be resolved first. After that...

When using

document.getElementsByClassName(...)
, it returns a collection. If your intention is to set the className = "show" on each element with the class name of k-grid-header, you will need to iterate over them.

The easiest way to achieve this is by utilizing querySelectorAll() because it provides a collection with a forEach() method for iteration:

document.querySelectorAll('.k-grid-header').forEach(el=>{ el.className = ""; //... etc });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Send data from an AJAX request to a Laravel controller

Here is the code for my ajax request where I am trying to pass values to a controller in Laravel. var deviceid="<?php echo $id; ?>"; var day="<?php echo $day; ?>"; $.ajax({ 'async': false, 'global': false, url ...

Having trouble sharing an image - error

I have a project in HTML where I need to send an image to a PHP script for uploading to a directory on the server. Here is the HTML form I am using: <form role="form" action="upload.php" method="post" enctype="multipart/form-data"> <div class="f ...

Updating a Specific Database Entry in Django Using Multiple Field Values

Hey there, I'm still learning the ropes and haven't had much time to really dive into it yet. My end goal is to create a "check-in/check-out" system by updating a timestamp from NULL to the current time based on employee number and work area. He ...

Limitations on jQuery Slider

I have implemented a jQuery Slider on my website to allow users to choose how much money they want to pay for upgrading their server. I want the slider to display in its entirety, but with a restriction that prevents users from sliding it below the amount ...

Accessing the req object in Node.js using Express

Currently, I am attempting to redefine the function send in order to include an express-session value with each response. Unfortunately, I seem to be encountering issues accessing the variable req within the definition of send. 01| let app = express(); 02| ...

Uploading files with Angular and NodeJS

I am attempting to achieve the following: When a client submits a form, they include their CV AngularJS sends all the form data (including CV) to the Node server Node then saves the CV on the server However, I am encountering difficulties with this proc ...

The value could not be retrieved because the input name depends on the array index

To determine the name of the input based on the array index, use the following method: <div id="editAboutSantences<%=i%>" class="edit-container"> <div class="input-container"> <label> content: </label> ...

I am a bit confused about how to use jQuery delegate

Is it necessary to create a new delegate function for each ajax action within dynamically loaded content, or can they be consolidated in the success handler? How should delegate functions be organized and when are they required? For instance, clicking the ...

React Weather App: difficulties entering specific latitude and longitude for API requests

I have successfully developed an app that displays the eight-day weather forecast for Los Angeles. My next objective is to modify the longitude and latitude in the API request. To achieve this, I added two input fields where users can enter long/lat values ...

The scrollbar on the side of my page seems to be malfunctioning

I'm having an issue with the collapsible sidebar and tabs on my angularjs page. The scroll bar is not appearing when there is overflow in the sidebar. I've tried setting the scrollbar height to auto and overflow-y to scroll, but it's not wor ...

Elements floating in space, stretching across the entire width

In my design, I have a fixed size layout with a centered content container. My goal is to have the menu (home, about, contact, login) span 100% of the screen width. You can view the current setup in this jsfiddle: http://jsfiddle.net/Hxhc5/1/ I am aimin ...

The color attribute in a Div container remains the same even when hovering over it

Hello everyone, I am new to stack overflow so please bear with me. I am currently working on this small webpage for my IT course and I have encountered a significant issue. .float1 { float:right; background-color:#A3635C; margin-top: 150px; ...

What is the best way to showcase navigation and footer on every page using AngularJS?

I'm in the process of building a Single Page Application. I've decided to create separate components for Navigation, Section, and Footer. The Navigation and Footer should be displayed on every page, while only the Section content changes when nav ...

Error: Interface declaration for _.split is missing in the Lodash.d.ts file

For my current typescript project that heavily relies on Lodash with lodash.d.ts, I've encountered an issue with the _.split function not being implemented yet. It's listed under the 'Later' section in the .ts file. I need to find a wo ...

What is the best way to align list items both to the right and left in my navigation

How can I justify list items both right and left in my navigation bar? <nav class="navbar navbar-expand-lg navbar-light bg-light"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" ...

Discovering the current active link and anchor tag details using jQuery in an unordered list

I am currently utilizing jQuery to work with 4 anchor tags inside an unordered list, and I would like to be able to determine the "current active link" when a user performs a search. This way, I can execute my query based on the selected anchor tag. How ca ...

Show the first letter of the first name using HTML

Is there a way to display the first letter of the first name followed by a period, a space, and then show the last name in asp/html/vb? ...

Exploring the jQuery Solution for Enhancing Dojo Widget Framework

My experience with Dojo in the past has been great, especially with its widget infrastructure. Being able to easily separate code and HTML content, having a seamless connection with the require system used by Dojo, and the convenient builder that compresse ...

Reintroducing multiple variables into an AJAX form POST success and assigning them as jQuery variables

I'm completely new to working with ajax technology. What I am attempting to do is retrieve some variables from a PHP file that I created specifically to handle the data from an HTML form and store it in a MySQL database table. After conducting some ...

Adjusting the target of the anchor dynamically

I have a WordPress theme with a built-in widget that allows you to insert social media links into sidebars or headers. All the social media links are contained within a div with a unique class called social-links. I want to add target="_blank" to all anc ...