Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove input placeholder using jquery

does anyone know how to remove input placeholder using jquery?

I want to do is if one of the inputbox got a value...all the inputbox placeholder will be remove....does anyone know how to do that?

<input type="text" name="name" placeholder="1.)">
<input type="text" name="age" placeholder="2.)">
<input type="text" name="address" placeholder="3.)">
like image 215
user3352395 Avatar asked Feb 28 '14 14:02

user3352395


People also ask

How to change placeholder jQuery?

The “placeholder” property is used to get or set the placeholder of an input text. This can be used to change the placeholder text to a new one. The element is first selected using a jQuery selector. The new placeholder text can then be assigned to the element's placeholder property.

How to remove placeholder on focus in JavaScript?

Inside the Watermark JavaScript function, first the event type is checked. If the event triggered is focus, then the value of the Placeholder attribute is copied to the REL attribute and the Placeholder attribute is removed.

How to change placeholder value using JavaScript?

To change the placeholder text of an input element with JavaScript, we can set the placeholder property of an element. Then we can set the placeholder attribute value for each input element by writing: document. getElementsByName('Email')[0].


4 Answers

Should work:

$(':input').removeAttr('placeholder');
like image 63
A. Wolff Avatar answered Oct 04 '22 04:10

A. Wolff


Get all the inputs, and attach a change event handler, inside the event handler get the value from all the inputs, join the values together, and if it's still nothing, none of the inputs have a value, if it has length, at least one of the inputs have value, and you can remove the placeholder attributes :

var inputs = $('input[type="text"]');

inputs.on('change', function() {
    if ( $.map(inputs, function(el) { return el.value; }).join('').length ) 
        inputs.removeAttr('placeholder');
});

FIDDLE

like image 40
adeneo Avatar answered Oct 04 '22 06:10

adeneo


I DONT RECCOMEND to remove placeholder

instead, make a focus, and this will automatically hide placeholder at that moment:

$(element).focus();
like image 24
T.Todua Avatar answered Oct 04 '22 04:10

T.Todua


.removeAttr()

var txtbox = $('input[type="text"]');
txtbox.change(function () {
    txtbox.removeAttr('placeholder');
});
like image 29
Tushar Gupta - curioustushar Avatar answered Oct 04 '22 06:10

Tushar Gupta - curioustushar