I have table which has about 50 rows. Each row has link, but I need replace this link by button. And I have a few way to do this but I don’t know which way is the best.
First way:
<form method="POST" action="some url">
<input type="submit" value="Clickable Button">
</form>
Second way:
<input type="button" value="Action button"
onclick="window.location='http://www.w3schools.com'" />
Third way:
<input type="button" class="actionButton" value="Action button"
data-link="http://www.w3schools.com"/>
And after I will add javascript code with jQuery:
$("input.actionButton").click(function () {
window.location = $(this).attr("data-link");
});
So, what is the best way?
Of those three, I’d go with a
formalthough if each link goes a different place, that’s a lot of forms just to replicate link functionality.But I have a fourth option for you: Style the link rather than replacing it. You can make the link look just about any way you want to, including almost entirely like a button. Since it is a link, that would be the most semantically-correct option (and less convoluted markup). Obviously, though, this depends on what the reason is that you have to replace the link with a button — e.g., if there’s some functional, rather than appearance, requirement for doing it.