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'; }">
I need the text field value to be blank regardless of whether the text field is clicked, not clicked or clicked out of.
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.
How do I remove the onblur value from the above mark-up?
The divs inside the menu also have onclick() events which execute the special processing. The problem is that the onclick() events never fire when the menu is clicked, because the input field's onblur() fires first and deletes the menu, including the onclick() s!
The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does bubble. The opposite of blur is the focus event, which fires when the element has received focus. The blur event is not cancelable.
You can use $(":disabled") to select all disabled items in the current context. To determine whether a single item is disabled you can use $("#textbox1").is(":disabled") . Save this answer.
Definition and UsageThe onblur attribute fires the moment that the element loses focus. Onblur is most often used with form validation code (e.g. when the user leaves a form field). Tip: The onblur attribute is the opposite of the onfocus attribute.
try this way :
$('#subscribe-field').removeAttr('onclick');
$('#subscribe-field').removeAttr('onblur');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With