Giter Site home page Giter Site logo

drench / coordinate.js Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 3.0 104 KB

Address HTML table cells by (x,y) coordinates, and know cell neighbors with north/south/east/west references

Home Page: http://dren.ch/js-table-coordinates/

License: Other

JavaScript 100.00%

coordinate.js's Introduction

coordinate.js

Did you ever wish you could address HTML table cells by X and Y coordinates?

<script src="coordinate.js"></script>
<script>

    var table = document.getElementsByTagName('table')[0];
    coordinate(table);

    // The origin (0,0) is the top, leftmost cell
    table.coordinates[3][2].innerHTML = '(3,2)';

</script>

Did you ever wish you could, given a table cell, easily address its neighbors?

<script src="coordinate.js"></script>
<script>

    var table = document.getElementsByTagName('table')[0];
    coordinate(table);

    var cell = table.coordinates[3][2];

    /* "edge" cells have 1 undefined direction
       corner cells have 2 undefined directions
       a cell in a 1x1 table would have all 4 directions undefined
       (but why would you do that?) */

    if (cell.north) cell.north.innerHTML = 'up';
    if (cell.south) cell.south.innerHTML = 'down';
    if (cell.west)  cell.west.innerHTML  = 'left';
    if (cell.east)  cell.east.innerHTML  = 'right';

</script>

Did you wish you could, given a table cell, know its X and Y coordinates?

<script src="coordinate.js"></script>
<script>

    var table = document.getElementsByTagName('table')[0];
    coordinate(table);

    var cells = table.getElementsByTagName('td');

    for (var i=0,td; td=cells[i]; ++i)
        td.onclick = function () {
            console.log('You just clicked on the cell at ' + this.x + ',' + this.y);
        };

</script>

I've barely tested this thing (though I did test it against table cells with colspans), and only on browsers that rhyme with "buyer stocks bee shot live". Enjoy.

coordinate.js's People

Contributors

drench avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

leparkour

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.