Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript and SVG: how do you increase the clickable area for an onClick event?
    text
    copied!<p>My script draws lines on the screen at a stroke-width of 3. The size of lines are ideal (visually) but they aren't very easy to click. </p> <p>As a rough example: </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; function selectStrand(evt) { current_id = evt.target.getAttributeNS(null, "id"); document.getElementById('main').innerHTML = current_id; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; Selected line: &lt;span id="main"&gt;&lt;/span&gt; &lt;?xml version="1.0"?&gt; &lt;svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" preserveAspectRatio="xMinYMin meet" viewBox="0 0 1000 1000"&gt; &lt;g id="buffer" transform="translate(10,0)"&gt; &lt;line id="blue-blue" x1="50" y1="50" x2="500" y2="50" style="stroke:blue; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-orange" x1="50" y1="70" x2="500" y2="70" style="stroke:orange; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-green" x1="50" y1="90" x2="500" y2="90" style="stroke:green; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-brown" x1="50" y1="110" x2="500" y2="110" style="stroke:brown; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-grey" x1="50" y1="130" x2="500" y2="130" style="stroke:grey; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-khaki" x1="50" y1="150" x2="500" y2="150" style="stroke:khaki; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-red" x1="50" y1="170" x2="500" y2="170" style="stroke:red; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-black" x1="50" y1="190" x2="500" y2="190" style="stroke:black; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-yellow" x1="50" y1="210" x2="500" y2="210" style="stroke:yellow; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-purple" x1="50" y1="230" x2="500" y2="230" style="stroke:purple; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-pink" x1="50" y1="250" x2="500" y2="250" style="stroke:pink; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;line id="blue-cyan" x1="50" y1="270" x2="500" y2="270" style="stroke:cyan; stroke-width: 4;" stroke-linecap="round" onclick="selectStrand(evt)"/&gt; &lt;/g&gt; &lt;/g&gt; &lt;/svg&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Is there a simple way to increase the area around each of the lines to make them easier to click?</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