Is there a way to create a popover menu in VueJS without using JQuery

I found exactly what I need in this helpful answer. It demonstrates a menu appearing when clicking on a table row. The dilemma is that it relies on JQuery...

Therefore, I am curious if achieving the same functionality without JQuery is possible. Maybe through VueJS, which happens to be the framework I am currently utilizing?

Answer №1

Translated the given example

let rows = document.querySelectorAll("tr");
    let btnPane = document.getElementById("button-pane");
    document.active = '';
  
    if (window.NodeList && !NodeList.prototype.forEach) {
        NodeList.prototype.forEach = Array.prototype.forEach;
    }

    btnPane.addEventListener("mouseover", function() {
        btnPane.style.display = "block";
        if(document.active)
            document.active.style.backgroundColor = "lightblue";
    });
    btnPane.addEventListener("mouseleave", function() {
        btnPane.style.display = "none";
        if(document.active)
            document.active.style.backgroundColor = "";
    });

    rows.forEach(function(row) {
        row.addEventListener("click", function(e) {
            var posLeft = e.clientX + 10;
            var posBottom = this.offsetTop + this.offsetHeight+8;
            btnPane.style.top = posBottom + "px";
            btnPane.style.left = posLeft + "px";
            btnPane.style.display = "block";
            document.active = this;
        });
        row.addEventListener("mouseleave", function() {
            btnPane.style.display = "none";
        });
    });
    table {
        border-collapse: collapse;
    }

    th, td{
        border-bottom: 1px solid #aaa;
    }

    #mytable tbody tr:hover {
      background-color: lightblue;
    }

    .button-pane {
      display: none;
      position: absolute;
      float: left;
      top: 0px;
      left: 0px;
      background-color: lightblue;
      width: 150px;
      height: 30px;
      padding: 0px;
      text-align: center;
    }

    .button-pane button {
      display: inline;
      cursor: pointer;
    }
    <table id="mytable" border="1" width="100%">
      <thead>
        <tr>
          <td>HEADER 1</td>
          <td>HEADER 2</td>
          <td>HEADER 3</td>
          <td>HEADER 4</td>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Item 1</td>
          <td>a</td>
          <td>aa</td>
          <td>aaa</td>
        </tr>
        <tr>
          <td>Item 2</td>
          <td>b</td>
          <td>bb</td>
          <td>bbb</td>
        </tr>
        <tr>
          <td>Item 3</td>
          <td>c</td>
          <td>cc</td>
          <td>ccc</td>
        </tr>
      </tbody>
    </table>
<div id="button-pane" class="button-pane">
  <button id="button1">Button 1</button>
  <button id="button2">Button 2</button>
</div>
    </div>

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

Obtain the time in a 12-hour format with "A.M." or "P.M." using Vuetify

Looking to implement a time picker in Vuetify that returns the time in a 12-hour format with "A.M." or "P.M." Encountering an error while trying to achieve this. Upon initial load, receiving a value of :undefined. Selecting a time in the morning gives n ...

What is the reason behind the failure of executing "this.$refs.inputField.focus()"?

I've set up an input field with a ref="inputField" as shown below: <input ref="inputField"> <button @click="btn">Click</button> When the button is clicked, I want the input field to receive focus. Here& ...

Executing a for loop just once in JavaScript

var door1 = {open: false,car: false,choose: false}; var door2 = {open: false,car: false,choose: false}; var door3 = {open: false,car: false,choose: false}; var carName = 0; var objectName = 0; var goatName = 0; var min = 1; var max = 4; var random = Math. ...

"Encountering problem with Angular HTTP services: the requested URL is not

Attempting to send data to API servers is resulting in a 404 error. Testing it on Postman shows that everything works fine. JSONP is being used for posting data due to cross-domain issues. The console displays the following: GET http://myapi.com/registrat ...

The function res.sendFile() does not display files on the browser

For the past few days, I've been facing a challenge. Does anyone have any suggestions? When I click on a login button, I authenticate the user, generate a token, store it in cookies, and then use it in the headers of a request to display the homepage. ...

JQuery email validation failing to function

I am new to JQuery and have created a basic validation script to verify email addresses. However, it does not seem to be working properly. Can anyone provide guidance on how to correct this issue? <script> $( "#email" ).blur(function() { var ...

Employing the power of JavaScript to enable the seamless toggle of an overlay

I have a div named "navbar_menu". On clicking this div, I want the visibility of the div named "nav_overlay" to fade in. Upon another click, I want it to fade back and become invisible again. Currently, I have set the div 'nav_overlay" to have ' ...

Is ES5 essentially the same as ES6 in terms of my lambda search?

After doing a search on an array using ES6, I am having trouble figuring out how to rewrite the code in ES5 due to restrictions with Cordova not allowing me to use lambda functions... $scope.Contact.title = $scope.doctitles[$scope.doctitles.findIndex(fu ...

I'm having trouble getting Tailwind CSS colors to work with my Next.js components. Any tips on how to apply background colors

https://i.stack.imgur.com/8RGS3.png https://i.stack.imgur.com/FRTOn.png Hey there! I'm currently experimenting with using Tailwind background colors in my Next.js project. However, I'm facing an issue where the background color is not being appl ...

Extracting the URL of the @font-face declaration in CSS with the use of JavaScript

Currently, my CSS file contains numerous @font-face tags. Each tag specifies a unique font-family and src URL. @font-face{ font-family: Garamond; src: url('ePrintFonts/pcl_91545.ttf'); } @font-face{ font-family: C ...

In JavaScript, a prompt is used to request the user to input a CSS property. If the input is incorrect,

Implement a while loop that continuously prompts the user to enter a color. If the color entered matches a CSS property such as blue, red, or #000000: The background will change accordingly, but if the user enters an incorrect color, a message will be dis ...

Tips for dynamically updating the API path in VUEX state

Currently, I am working on dynamically updating the API path within my Vuex state. When the page loads, I have set a default path of "example.com/api/datasetA.json" in Vuex. However, I would like this path to be updated to "example.com/api/datasetB.json" b ...

The jQuery onClick function functions effectively for the initial two clicks; however, it ceases to

I am currently experimenting with jQuery to dynamically load a specific div from another page on my server into a designated section on the existing page. While the code is successfully functioning for the first two clicks on the website, it fails to work ...

A guide on organizing an array of objects by a specific property using a separate array

Here is the array I am working with: var arr = [ { count: 27, dataRil: "08/06/21", subCateg: "FISH", }, { count: 22, dataRil: "08/06/21", subCateg: "DOG", }, { count: 28, dat ...

Encountering IntegrityError from django.db.utils while trying to send a post request using axios in a Vue

As I delve into the realm of web development, I find myself encountering a challenge that requires your expertise. I am attempting to transmit data to an endpoint in an API which I have constructed using the Django Rest Framework with Vue and Axios. Howeve ...

Unspecified reference to this.$refs.canvas in Vue.js

Currently working on a new project that involves using vuejs3 and canvas, but encountering some issues with the canvas element. Any suggestions or ideas would be greatly appreciated! Within my project, I am receiving undefined when trying to access this.$ ...

Retrieve JSON information from a document through JavaScript

Is it possible to fetch JSON data using JavaScript without relying on jQuery? I am only interested in retrieving data using pure JavaScript. Here is an example of my JSON file: {"JsonProjectIDResult":[{"_capacity":15,"_description":"Meeting Room","_dev_d ...

Strategies for preserving context throughout an Ajax request

In my project, I am looking to implement an Ajax call that will update a specific child element within the DOM based on the element clicked. Here is an example of the HTML structure: <div class="divClass"> <p class="pClass1">1</p> &l ...

Caught up: TypeScript not catching errors inside Promises

Currently, I am in the process of developing a SPFx WebPart using TypeScript. Within my code, there is a function dedicated to retrieving a team based on its name (the get() method also returns a promise): public getTeamChannelByName(teamId: string, cha ...