Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:32:17+00:00 2026-06-10T18:32:17+00:00

I need to select all td’s within my table with a drag event. What

  • 0

I need to select all td’s within my table with a drag event. What I am trying to achieve is to create a date range based on my first selected td, until the last selected td, but they can span over multiple rows.
At the moment, I am using nextUntil() with andSelf() to include the last selected, but it only selects td’s within the current tr.
Below is a sample of my code.
Any help please.

this.BindCalendarMouseDrag = function () {
        var isMouseDown = false;
        var isHighlighted;
        var selectedDays = [];
        $(".tabCalendarContainer tr.trCalWeek td")
            .mousedown(function () {
                isMouseDown = true;
                $(this).addClass("highlighted");
                isHighlighted = $(this).hasClass("highlighted");
                selectedDays.push($(this));
                return false; // prevent text selection
            })
            .mouseover(function () {
                if (isMouseDown) {
                    $(this).addClass("highlighted", isHighlighted);

                    var firstSelectedDay = selectedDays[0];
                    firstSelectedDay.nextUntil($(this)).andSelf().add($(this)).addClass("highlighted", isHighlighted);

                    selectedDays.push($(this));
                }
            })
            .bind("selectstart", function () {
                return false;
            });

        $(document).mouseup(function () {
            isMouseDown = false;
            //alert(selectedDays.length);
        });
    };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:32:18+00:00Added an answer on June 10, 2026 at 6:32 pm

    I took the liberty of constructing a fiddle that illustrates a calendar with draggable weekdays. It doesn’t cater for BACKWARDS dragging yet, but you should be able to easily adjust the code to accommodate it.

    $(document).ready(function () {
        $("td.week").hover(
            function () { $(this).addClass("hover"); },
            function () { $(this).removeClass("hover"); }
        );
        var busySelecting = false;
        var selectedDays = [];
        var contains = function(day) {
            for (var d in selectedDays) {
                if (selectedDays[d].text() == day.text())
                    return true;
            }
            return false;
        };
        $("td.week").mousedown(function () {
            selectedDays = [];
            $("td.week").removeClass("selected");
            busySelecting = true;
            if ($(this).text() != "") {
                $(this).addClass("selected");
                selectedDays.push($(this));
            }
            return false;
        });
        $("td.week").mouseover(function () {
            if (busySelecting &&
               $(this).text() != "")
            {
                var busyHovering = $(this);
                $("td.week").each(function () {
                    if ($(this).text() != "" &&
                        parseInt($(this).text(),10) > parseInt(selectedDays[0].text(),10) &&
                        parseInt($(this).text(),10) <= parseInt(busyHovering.text(),10) &&
                        !contains($(this))) {
                        $(this).addClass("selected");
                        selectedDays.push($(this));                
                    }
                });
                $(selectedDays).each(function () {
                    if (parseInt($(this).text(),10) > parseInt(busyHovering.text(),10)) {
                        $(this).removeClass("selected");
                        selectedDays.pop($(this));
                    }
                });
                selectedDays.push($(this));
            }
        });
        $(document).mouseup(function () {
            busySelecting = false;
            alert("You selected the following range: " +
                  selectedDays[0].text() + " - " +
                  selectedDays[selectedDays.length - 1].text());
        });
    });
    td
    {
        padding:10px;
        cursor:default;
    }
    td.hover
    {
        background:#EEE;
    }
    td.weekend
    {
        background:silver;
    }
    td.selected
    {
        background:#5EE;
    }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <table>
        <tr>
            <td class="weekend"></td>
            <td class="week"></td>
            <td class="week">1</td>
            <td class="week">2</td>
            <td class="week">3</td>
            <td class="week">4</td>
            <td class="weekend">5</td>
        </tr>
        <tr>
            <td class="weekend">6</td>
            <td class="week">7</td>
            <td class="week">8</td>
            <td class="week">9</td>
            <td class="week">10</td>
            <td class="week">11</td>
            <td class="weekend">12</td>
        </tr>
        <tr>
            <td class="weekend">13</td>
            <td class="week">14</td>
            <td class="week">15</td>
            <td class="week">16</td>
            <td class="week">17</td>
            <td class="week">18</td>
            <td class="weekend">19</td>
        </tr>
        <tr>
            <td class="weekend">20</td>
            <td class="week">21</td>
            <td class="week">22</td>
            <td class="week">23</td>
            <td class="week">24</td>
            <td class="week">25</td>
            <td class="weekend">26</td>
        </tr>
        <tr>
            <td class="weekend">27</td>
            <td class="week">28</td>
            <td class="week">29</td>
            <td class="week">30</td>
            <td class="week">31</td>
            <td class="week"></td>
            <td class="weekend"></td>
        </tr>
    </table>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this mysql orders table: (id,user_id,skin,item,date,reference,price,to_who) I need to select all users, with
I need some help with SQL Query. I am trying to select all records
I'd like to select all entries from a table where date is the last
I need select all elements from a set whose Id property is contained within
I need to select all data in table created not less than 24 hours
Need help with PHP/MySql. Need to select all the records from 'today'. My table
I have a list of prices ordered by date. I need to select all
I need to select all but the first row (header) in all tables (GridView)
I need to select all IDs from one table with columns ID and X
I have a table OrderSpecs . I need to select all of the rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.