Dilip Raj Baral
Dilip Raj Baral

Reputation: 3070

Javascript - clear an attribute of an element

I have an HTML element:

<a id="link" href="javascript : void(0);" onclick="jsFunction();">Some Text</a>

And when a button is clicked I want the onclick attribute to be cleared. Something like

<a id="link" href="javascript : void(0);" onclick="">Some Text</a>

I tried doing this way :

document.getElementById('link').onclick="";

which didn't work.

Upvotes: 1

Views: 4251

Answers (1)

Ahsan Khurshid
Ahsan Khurshid

Reputation: 9469

Use removeAttribute()

document.getElementById('link').removeAttribute('onclick');

SEE DEMO

Upvotes: 4

Related Questions