Blakeinator
Blakeinator

Reputation: 65

change html form element placeholder with jquery

I need help changing the placeholder value on a input field with javascript, preferably JQuery.

<input id="someinput" value="" placeholder="Change This With JS" type="text">

Upvotes: 3

Views: 4211

Answers (2)

chrisvillanueva
chrisvillanueva

Reputation: 1359

here's a quick demo for you:

the fiddle code http://jsfiddle.net/nickadeemus2002/H7MG7/

just use jquery's .attr() method to changed the string.

Upvotes: 1

Tats_innit
Tats_innit

Reputation: 34107

demo like this: http://jsfiddle.net/qcNFF/ ?

Good read: http://api.jquery.com/prop/

code

$(function() {
    alert(' Before change => ' + $('#someinput').prop('placeholder'));
    $('#someinput').prop('placeholder', "text changed- hulk");
    alert(' After change => ' + $('#someinput').prop('placeholder'));
});​

Upvotes: 5

Related Questions