Pudding
Pudding

Reputation: 553

Set HTML text input to null with JQuery

Using JQuery event handlers I want to adjust the default value of a HTML text input and set it to empty.

The input

<button id="setColor">Set Color</button>
<input type="text" id="colorText">

The function

$("#setColor").on("click", function ()
{
    document.getElementById('#colorText').defaultValue = "";
});

I have also tried

$("#colorText").defaultValue = "";
$("#colorText").val = "";
$("#colorText").value = "";

but every time I click the SetColor button it seems to keep its previously set default value.

document.getElementById('colorText').defaultValue = "#0000ff";

Upvotes: 2

Views: 14181

Answers (3)

khoekman
khoekman

Reputation: 1153

$("#colorText").val("");

You can try this with jquery.

Upvotes: 0

Murad Hasan
Murad Hasan

Reputation: 9583

Your question is not cleared to me, But i got a simple mistake in your code, you write extra # in getElementById

try this:

$("#setColor").on("click", function ()
{
    document.getElementById('colorText').value = "";
});

Are you trying to reset the textbox color or want to reset the value?

Upvotes: 2

Pudding
Pudding

Reputation: 553

document.getElementById('colorText').value = '';

Upvotes: 0

Related Questions