I have two functions in my jQuery which manage two buttons and then display them. What I want is for the buttons to be displayed in the center, but align=center doesn’t work. Does anyone know how to do this in my jQuery code?
jQuery code below:
function insertQuestion(form) {
var $answer = $("<table class='answer'></table>");
$('.allBtns:first-child').each(function() {
var $this = $(this);
var $allBtnsClass = '';
$allBtnsClass = $("<input class='allBtns btnsAll' type='button' style='display: inline-block;' value='Select All Answers' onClick='selectAll(this);' />")
.attr('name', $this.attr('name'))
.attr('value', $this.val())
.attr('class', $this.attr('class'));
}
$answer.append($allBtnsClass);
});
$('.allRemoveBtns:first-child').each(function() {
var $this = $(this);
var $removeBtnsClass = '';
$removeBtnsClass = $("<input class='allRemoveBtns btnsRemove' type='button' style='display: inline-block;' value='Remove All Answers' onClick='removeAll(this);' />")
.attr('name', $this.attr('name'))
.attr('value', $this.val())
.attr('class', $this.attr('class'));
}
$answer.append($removeBtnsClass);
});
$tr.append($answer);
}
I don’t know if this is your only issue, but you are placing your buttons in a
table; tables should not directly containinputelements. I don’t think you need a table anyway. If you make your container element adiv(say, with the classanswers), you can just have this style in your stylesheet:Then, if you stop setting
display: inline-blockon yourinputbuttons, they should display inline by default, and then thetext-align: centerof the container should take care of centering them.Your JavaScript also contains too many
}s. They are only needed when pairing with{s.I hope that helps.