admin管理员组文章数量:1416322
In HTML I have text in text tag:
<text id="aaa" > text</text>
Is it possible to add onclick event to this ?
Tried
var a = document.getElementById('aaa');
a.elemm.addEventListener('click', function(){ alert('blah');}, false);
In HTML I have text in text tag:
<text id="aaa" > text</text>
Is it possible to add onclick event to this ?
Tried
var a = document.getElementById('aaa');
a.elemm.addEventListener('click', function(){ alert('blah');}, false);
Share
Improve this question
edited Dec 2, 2016 at 8:48
xShirase
12.4k4 gold badges54 silver badges86 bronze badges
asked Dec 2, 2016 at 8:43
AnuketAnuket
3398 silver badges24 bronze badges
1
- your code is working fine just remove the a.elemm part a. itself will work fine – GraveyardQueen Commented Dec 2, 2016 at 8:47
3 Answers
Reset to default 3You're almost there! Just change a.elemm.addEventListener
to a.addEventListener
:
var a = document.getElementById('aaa');
a.addEventListener('click', function(){ alert('blah');}, false);
<text id="aaa"> text</text>
This works:
var a = document.getElementById('aaa');
a.addEventListener('click', function(){ alert('blah');}, false);
You just have a little mistake
try to something like this.
<text id="aaa" > text</text>
var a = document.getElementById('aaa');
a.addEventListener('click', function(){ alert('Text has been changes');}, false);
本文标签: javascriptAdd onclick function to text tag elementStack Overflow
版权声明:本文标题:javascript - Add onclick function to text tag element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745250729a2649809.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论