Cannot disable onclick/onblur values for text field via jQuery

Dominor Novus picture Dominor Novus · Oct 11, 2012 · Viewed 7.3k times · Source

What I have

I have a text field, the mark-up of which I cannot directly edit:

<input type="text" name="email" value="Email Address" id="subscribe-field" 
onclick="if ( this.value == 'Email Address' ) { this.value = ''; }" 
onblur="if ( this.value == '' ) { this.value = 'Email Address'; }">

What I need

I need the text field value to be blank regardless of whether the text field is clicked, not clicked or clicked out of.

What I've tried

I can disable the value:

$('#subscribe-field').val('');

I've tried to disable the onclick and onblur values:

$('#subscribe-field').click(function() { return false; });
$('#subscribe-field').off('click');
$('#subscribe-field').unbind('click');

...however, the value reappears as soon as I click outside of the text field.

My question

How do I remove the onblur value from the above mark-up?

Answer

Mahmoud Farahat picture Mahmoud Farahat · Oct 11, 2012

try this way :

$('#subscribe-field').removeAttr('onclick');

$('#subscribe-field').removeAttr('onblur');