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 8495187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:30:14+00:00 2026-06-10T23:30:14+00:00

I have a table with 8 <tr> s, each with 8 <td> s, each

  • 0

I have a table with 8 <tr>s, each with 8 <td>s, each with a data-x value and data-y value of between one and eight, i.e. an 8×8 grid for a chessboard.

Given that bishops can only move diagonally and I have the coordinates of the starting and ending squares, what is the most efficient way to find all the <td> elements in the ‘path’.

Example:

// coordinates representing a bishop move from d6 (4, 6) to h2 (8, 2)
var from = {
    x: 4,
    y: 6
},
to = {
    x: 8,
    y: 2
}

// code to select squares e5 (5,5), f4 (6,4) and g3 (7,3)

How could I select these elements:

td[data-x="5"][data-y="5"],
td[data-x="6"][data-y="4"],
td[data-x="7"][data-y="3"]

in the most efficient way, baring in mind the from and to are set dynamically?

For information, I have written a function used elsewhere to check if the bishop has moved diagonally to start with:

function is_valid_bishop_move(from, to){
    var tan_theta = (to.y - from.y) / (to.x - from.x);
    if( tan_theta === 1 || tan_theta === -1 ){
        return true;
    }else{
        return false;
    }
}
  • 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-10T23:30:16+00:00Added an answer on June 10, 2026 at 11:30 pm

    I can only think of something like this:

    var from = {
        x: 4,
        y: 6
    },
    to = {
        x: 8,
        y: 2
    }
    
    var delta_x = (to.x - from.x > 0 ? 1 : -1),
        delta_y = (to.y - from.y > 0 ? 1 : -1),
        dest_x = from.x + delta_x,
        dest_y = from.y + delta_y,
        selector = '';
    
    while (dest_x != to.x) {
        selector += 'td[data-x="' + dest_x + '"][data-y="' + dest_y + '"],';
        dest_x += delta_x;
        dest_y += delta_y;
    }
    
    selector = selector.replace(/,$/, '');
    
    console.log(selector);
    ​
    

    http://jsfiddle.net/zerkms/gtEwV/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data table filled with text in each table row. How do
I have a table, with cells, and each cell has a data-type. I have
Ok, I have a table which contains multiple rows. Each row contains some data
I have about 1 million data in users table. Now I want each user
I have two db tables. One table contains Forecast data. The second table contains
I have a MySQL table of correlation data that I need to extract. I
I have one table that stores values with a point in time: CREATE TABLE
In each table have many number of rows with amount. Like this i have
I have a table where each row has a description field as well as
I have a table where each row has 13 TD elements. I want to

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.