Anuket
Anuket

Reputation: 339

Add onclick function to text tag element

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);

Upvotes: 0

Views: 9197

Answers (3)

Pravin Vavadiya
Pravin Vavadiya

Reputation: 3207

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);

Upvotes: 0

xShirase
xShirase

Reputation: 12399

You'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>

Upvotes: 3

ixpl0
ixpl0

Reputation: 756

This works:

var a = document.getElementById('aaa'); 
a.addEventListener('click', function(){ alert('blah');}, false);

You just have a little mistake

Upvotes: 0

Related Questions