So I'm trying to create a new button dynamically in javascript and using some jquery. This function doesn't work for some reason. It seems to falter at the append function. Any suggestions?
Here's the .js function
SwapButton: function(){
var element = document.createElement('input');
element.setAttribute("type", "button");
element.setAttribute("value", "Trash Letters");
element.setAttribute("onClick", "GB.swapLetters()");
document.getElementsByTagName('input')[0].appendChild(element);
$('input[type="button"]').append(element);
}
The html. The new button should be added to where the input types are
<body>
<div class="hero-unit">
<div class="row-fluid">
<div class="span8"></div>
<div id="timer" class="span4"></div>
</div>
<div class="row-fluid">
<div id="score-board" class="span8"></div>
</div>
<div class="row-fluid span12" id="word-area">
</div>
<div class="row-fluid" id="row1">
<div id="1" class="span2"></div>
<div id="2" class="span2"></div>
<div id="3" class="span2"></div>
<div id="4" class="span2"></div>
<div id="5" class="span2"></div>
<div id="6" class="span2"></div>
</div>
<div class="row-fluid" id="row2">
<div id="7" class="span2"></div>
<div id="8" class="span2"></div>
<div id="9" class="span2"></div>
<div id="10" class="span2"></div>
<div id="11" class="span2"></div>
<div id="12" class="span2"></div>
</div>
<input type="button" onClick="GB.check()" value="Check"></input>
<input type="button" onClick="GB.clear()" value="Clear"></input>
<input type="button" onClick="GB.start()" value="Start"></input>
</div>