4 ms·
<button onclick="window.location.href='https://example.com';">I'm a button with a link</button> This code from the demo shows, why not using classes to style a
by jebronie 5y ago
<button onclick="window.location.href='https://example.com';">I'm a button with a link</button>
This code from the demo shows, why not using classes to style a website is a misguided idea.
Maybe something like this would be a better idea if you absolutely must avoid classes:
https://jsfiddle.net/qa2cdj4v/ https://jsfiddle.net/qa2cdj4v/
<strong><a href="#">Button</a></strong>
strong > a:first-child:last-child {
display: inline-block;
background: red;
color: white;
padding: 10px;
font-weight: normal;
}
- fath0m 5y agowhy not just use <form action="https://example.com"><button type="submit">Link button</button></form> no need for JS
- yurishimo 5y agoWhy not use use an anchor tag?
- stefanfisk 5y agoBecause you cannot make `form` `inline-block` for only this instance without classes.
- thomascz 5y agoI can't understand why so many websites use an onclick handler on a button to redirect to websites. It's not hard to even find something like <a href="#" onclick="location.href='https://example.com';">click https://example.com';">click here</a> The worst part is that it's not just random websites doing this, this can be found on most FAANG websites as well.
- notjustanymike 5y agoYep that's a pretty fundamental accessibility failure.