0

I'm attempting to reuse the variable "startGame", variable through which I declare an "a" element to be appended to the "table" element, in order to test for its own presence posteriorly. The code I've written for doing so is the following:

//Helper function to set HTML Tags attributes
function setAttributes(element, attributes)
{ for (var key in attributes) { element.setAttribute(key, attributes[key]); } }

//Opening screen
var startGame = document.createElement("a");
setAttributes(startGame,
{
    "style" : "float:left; width: 100%; text-align: center;",
    "onclick" : "dealHands()"
});
startGame.appendChild(document.createTextNode("Play"));

var table = document.getElementById("table");
table.appendChild(startGame);

function dealHands()
{
    if (table.childNodes[0].nodeValue == startGame)
    { table.removeChild(startGame); }
    ...
}

So far, the code fails to perceive "startGame" and nothing happens.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Guilherme de Abreu
  • 149
  • 1
  • 1
  • 5
  • Is the element with the ID `"table"` actually a `` element? If so, that'll be part of the problem. Please include your `HTML` in the question.
    –  Jul 24 '13 at 20:01
  • What errors appear in your browser's console? – Andy G Jul 24 '13 at 20:06
  • BTW Nice word **posteriorly** ;) – Andy G Jul 24 '13 at 20:06
  • @Crazy Train: Nope, Its a div. Actually I've already solved the problem, but I can't answer my own question because I don't have enough "reputation". I just had to remove the ".nodeValue" from the if statement in order to make a comparison between two HTML elements instead of comparing a value with a HTML element. Andy G: Thanks. Actually, in portuguese "posteriormente" isn't uncommon. – Guilherme de Abreu Jul 24 '13 at 20:14

2 Answers2

0

You cannot set the style attributes using this:

"style" : "float:left; width: 100%; text-align: center;"

they have to be set individually. But IE doesn't support changing style in this way. You need:

element.style.cssFloat = "left";    // etc.

Discussed here

Also, I wouldn't use table as an ID.

Community
  • 1
  • 1
Andy G
  • 19,232
  • 5
  • 47
  • 69
0

I just had to remove the ".nodeValue" from the if statement in order to make a comparison between two HTML elements instead of comparing a value with a HTML element.

Guilherme de Abreu
  • 149
  • 1
  • 1
  • 5