I'm having trouble figuring this out. I've created a table, and I want to use clickable buttons (not the arrow keys) to navigate through each cell and mark that cell as yellow. The table builds and I can navigate down, but not up. Is there an easier way to traverse the table with the clickable buttons. I have spent way too much time figuring this out to really care to admit.
edit: We're supposed to be using and navigating through the DOM to the elements.
edit 2: Fixed the issue of cell's not marking. And the buttons correctly traverse both down and up, but the UP goes into the header row which I do not wan. Still can't figure out going right/left. I updated the pastebin link.
edit 3: I seem to have gotten it working now. Adding JSfiddle link: http://jsfiddle.net/rq3tjpu1/
function buildTable() {
var newTable = document.createElement("table");
//Var I = Rows
//Var J = columns
for (var i = 0; i < 4; i++) {
var tr = document.createElement('tr');
for (var j = 0; j < 4; j++) {
var td = document.createElement('td');
if (i == 0 && j != 4){
td.appendChild(document.createTextNode("Header "))
td.appendChild(document.createTextNode((j+1)))
tr.appendChild(td)
}
else {
td.appendChild(document.createTextNode(i))
td.appendChild(document.createTextNode(", "))
td.appendChild(document.createTextNode((j+1)))
tr.appendChild(td)
}
}
newTable.appendChild(tr);
}
document.getElementById("tableHere").appendChild(newTable);
newTable.setAttribute("border", 3);
newTable.style.width = '50%';
return newTable;
}
Why not assign a specific value ( could be in the form of attributes) for the position of each cell? So each cell would have an X and Y value . Then you would keep a variable storing the current X and Y values. Once an arrow key has been pressed, you can use jQuery to select the cell with the required X and Y values, so for Up button that would be: (X, Y+1) , Down button (X, Y-1), Left (X-1, Y), Right (X+1, Y).
In this case it would be a good idea to use verification on the min/max X and Y values.
Hope this helps.
Currently I've got the following JSON feed: var data = { "feeds": { "regions": [{ "name": "Lichtenberg", "id": "01408.b", "suburbs": [{ "name": "Fennpfuhl", ...
Currently I've got the following JSON feed: var data = { "feeds": { "regions": [{ "name": "Lichtenberg", "id": "01408.b", "suburbs": [{ "name": "Fennpfuhl", ...
I need a textarea to include a set of double quotes at the start and end of the textarea value. The below code works in that double quotes are added to the start and end of the field, but if the user ...
I need a textarea to include a set of double quotes at the start and end of the textarea value. The below code works in that double quotes are added to the start and end of the field, but if the user ...
I have an URL looking like this: https://www.website.com/dk/da/home/category/ I am trying to remove the last forward slash and the text before it, untill it reaches the new forwardslash. Meaning i ...
I have an URL looking like this: https://www.website.com/dk/da/home/category/ I am trying to remove the last forward slash and the text before it, untill it reaches the new forwardslash. Meaning i ...
I have a function to call API from the server like this: getDataSet(callback) { request.open('POST', `${apiPath}`); request.setRequestHeader('Content-Type', 'application/x-...
I have a function to call API from the server like this: getDataSet(callback) { request.open('POST', `${apiPath}`); request.setRequestHeader('Content-Type', 'application/x-...