やりたいこと
svg要素を画面上でクリックした際にクリックイベントを発火させたい。
現状コード
javascript
1 $(window).on('load', function () { 2 var classname = document.getElementsByClassName('hoge').contentDocument; 3 4 $(classname).on('click', function () { 5 alert('反応した'); 6 }); 7 });
html
1 <g id="PA18" class="hoge" 2 transform="translate(-0.12368393,25.421501)"> 3 <rect style="display:inline;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.07969642;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" 4 id="RECT6-1" 5 width="7.55512" 6 height="18.46151" 7 x="46.504688" 8 y="65.076912" /> 9 <text xml:space="preserve" 10 style="font-style:normal;font-weight:normal;font-size:4.57837629px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26413709" 11 x="48.90873" 12 y="75.833351" 13 id="text1334-5" 14 transform="scale(1.0001351,0.99986491)"><tspan id="tspan1332-0" 15 x="48.90873" 16 y="75.833351" 17 style="stroke-width:0.26413709">6</tspan></text> 18 </g>
コンソールにてvar classname = document.getElementsByClassName("hoge");でconsole.log()をするとちゃんとクラス名が出ます。
javascript
1var classname = document.getElementsByClassName("hoge"); 2console.log(classname);
構文が間違っているのでしょうか。
ご教授お願いいたします。
回答1件
あなたの回答
tips
プレビュー