Get notified about the number of cells you've selected by simply dragging on a table

Is there a way to display the number of selected cells in a table when dragging with the mouse? I have a table set up, and I'd like to create an alert that shows how many cells are selected while dragging. Here is the link to my fiddle: http://jsfiddle.net/kannankds/q35vm6qv/1/

<table style="width:300px" id="mytable">
<tr>
<th>Firstname</th>
<th>Lastname</th>   
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>  
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>    
</tr>
<tr>
<td>John</td>
<td>Doe</td>    
</tr>
</table>

Answer №1

To easily retrieve the count, you can use the following method:

let totalHighlighted = $('.highlighted').length;

The timing of when to execute this code will vary based on your specific requirements.

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

Exploring a JSON file to generate a customized array for implementing autocomplete functionality in jQuery

I'm currently working on developing an autocomplete feature for a search bar that will display names of places in Norway. The data is being fetched from a REST API URL provided by a third party. As an example, when the input is "st" there are two res ...

Issue with offset calculation in bootstrap table occurs when the bootstrap-table is closed and the window is resized

In a recent project, I utilized the bootstrap table. However, upon closing the bootstrap table with the following script: $(document).ready(function () { $(".removetable").click(function (e) { $(".table-aria").remove(); ...

What is the best way to shut down a browser using C#?

After clicking the Login button, I want to automatically close the browser if the login is successful. protected void btnLogin_Click(object sender, AuthenticateEventArgs e) { if (isAuthenticated) { // close the browser } } Since I am not using AJAX, thi ...

Achieving equal height for two divs and centering them

Is it possible to align the height of two floated divs so that the second div slips down, and the container width automatically adjusts to fit the child width while centering the divs? I apologize for any language errors. :( <!DOCTYPE html PUBLIC "-//W ...

How to use Selenium to interact with an array of string elements and perform clicks

I have a String array that I obtain from either a text file or CSV. My goal is to use Selenium to click on each checkbox element corresponding to the elements in the array. The checkboxes follow this naming convention: 1.0.50.gecb16, 1.1.50.gecb16, 1.2. ...

Implement a counter in a JavaScript table, initializing it to zero

I have successfully written my code, but there is one issue. The first row is starting with the number one instead of zero. I'm looking for suggestions on how to start from zero. Any help would be greatly appreciated. Thanks! <script> var tabl ...

Strategies for patiently waiting for an object to appear before loading the HTML

After logging into my service, I download data from a REST API, and based on that data, I display certain tabs. However, I am experiencing issues with loading the HTML content once the data has been retrieved. The ngif directive at the beginning of the H ...

Is there a way to implement a "report" button for sending messages that doesn't require using email?

I am in need of a button that reads "Report a typo" and alerts me when it is clicked on a specific page. The project I am working on consists of multiple short pages with just a few paragraphs in each HTML template. It would be helpful for me to have a way ...

What is the most effective method to verify if all elements in an array fall within a specified range

What is the most effective method to verify if all array values fall within a specific range? For instance: $range = range(10, 40); $array1 = array(10, 20, 40); // OK $array2 = array(11, 22, 42, 30); // FALSE $array3 = array(50); // OK $array4 = arra ...

Incorporate this layout employing Java

Is there a way to achieve the following format in Java? Desired Output: 1 8 15 2 9 16 3 10 4 11 5 12 6 13 7 14 Java Code: int a = 1; for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ System.out.print(a++); } System.out.println(""); } ...

What is the best way to set the keyframes CSS value for an element to 0%?

Would like to create a progress indicator div using CSS animations? Check out the JSBin link provided. The desired behavior is to have the div width increase from 30% to 100% when the user clicks on stage3 after stage1, rather than starting from 0%. Althou ...

What is the method to assign a value to ng-class in Angularjs?

I need to categorize items in a list by assigning them classes such as items-count-1, items-count-2, items-count-3, items-count-4, based on the total number of items present. This is how I would like it to appear: li(ng-repeat="area in areas", ng-class=" ...

Utilizing jQuery to Maintain State Across Page Refreshes with Cookies

Currently, I am attempting to create a script that can retain its state even after the page is refreshed. Here is my progress so far: Utilizing jQuery: $(window).ready(function() { var voteId = $('.gallery-item a'); $(voteId).click(function() ...

SyntaxError: The input on line one ended unexpectedly and was not caught

This issue is commonly associated with messy close parentheses, however, the error is occurring on line 1 of the file! Below is the javascript code from (filename: calculate.js) var colors = new Array(); colors["SILVER"] = -2; ... Although there is m ...

Media Queries elude my complete comprehension

Can anyone provide a brief overview? For example, should buttons and images, as well as a footer, all be placed in one Media Query or kept separate? I'm feeling overwhelmed by this. ...

Avoid having Masonry load all divs simultaneously

I have experience using jQuery Masonry on Tumblr, but now I want to incorporate it into my portfolio website for displaying my photography. However, I'm struggling to find a solution that allows sets of images to load in as the user scrolls to the bot ...

What is the best way to save String arrays to a text file in Java with the help of PrintWriter?

Looking for assistance in writing the contents of array objects to a text file using Printwriter. I'm a beginner, so any simple ideas would be greatly appreciated! Astronauts[0][0] = new Passengers(-1, "", 1, 0, 0, "", "", 0, "", "", "", "", ""); ...

How can I make <p> elements change color when scrolling?

My Goal https://i.sstatic.net/JbdXR.gif I aim to bring attention to the <p> element as the user scrolls on the page. Initially, the opacity is set to 0.3, but I want it to change to 1 gradually as the user scrolls down. My Attempt window.o ...

From jQuery function to an npm module

If you're looking to create a new jQuery plugin, why not follow along with the tutorial below? You can find the full guide at https://learn.jquery.com/plugins/basic-plugin-creation/ (function ( $ ) { $.fn.customPlugin = function() { this.css( ...

Angularjs is struggling to connect data to the user interface

It seems that the array is not binding properly in the UI. In the HTML code, I am using dataTables. The variable $scope.successMessage is also not binding to the UI. I have tried multiple approaches but none seem to be working. Here is a snippet of th ...