Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use a <code>&lt;button&gt;</code> or <code>&lt;input type="submit"/&gt;</code> with CSS <code>background</code> styles applied.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; .hoverable { background: #FFFFFF url(path/to/background.png) top left no-repeat; height: 32px; /* height and width match your background.png dimensions */ width: 64px; } .hoverable:hover { background-image: url(path/to/background-hover.png); } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; ... &lt;button type="submit" class="hoverable"&gt;&lt;/button&gt; &lt;!-- or &lt;input type="submit" class="hoverable"/&gt; --&gt; &lt;!-- or &lt;button type="button" class="hoverable"&gt;&lt;/button&gt; if you don't want submit behavior --&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Using a form input makes the most sense semantically, especially with your concerns about accessibility. People using accessibility tools probably aren't expecting to encounter a <code>&lt;div&gt;</code> or <code>&lt;img&gt;</code> and be expected to perform an input event on it (I could be wrong, I'm not entirely familiar with how such tools work).</p> <p>The fact that the application is dynamic/ajaxy/etc. shouldn't be a barrier to you using the appropriate markup elements and using CSS to style it appropriately.</p> <p><strong>Edit:</strong></p> <p>Regarding the <code>&lt;input&gt;</code> not working: if you return false from whatever gets invoked when the button is clicked, it won't continue execution (i.e. submit the form). Example:</p> <pre><code>&lt;button type="submit" onclick="handleClick();"&gt;&lt;/button&gt; ... function handleClick() { // ajax call return false; } </code></pre> <p>On top of that, using a <code>&lt;button type="button"&gt;&lt;/button&gt;</code> shouldn't even submit the form at all. Some browsers default the <code>type</code> to "submit", so you'd want to explicitly define <code>type="button"</code> to make sure it's not treated as a submit.</p> <p>Obviously, this will be different than your prototype code, but you get the picture; the gist of it is that the event handler needs to return <code>false</code>. And <code>&lt;button&gt;</code>/<code>&lt;input&gt;</code> can be styled just as well as an <code>&lt;img&gt;</code> or <code>&lt;div&gt;</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload