Dimitar Dimitrov
Dimitar Dimitrov

Reputation: 15158

Clearing the default value of an input element in IE

I have a input element with a default value set and I'm trying to clear it, this is how it looks like:

<input id="something" type="text" value="test" />

I'm trying following:

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

Which seems to be working in Chrome, but not in IE9/IE10. Any ideas, or a workaround ?

Here is a fiddle: http://jsfiddle.net/TBB4N/1/

Upvotes: 0

Views: 101

Answers (5)

Praveen
Praveen

Reputation: 56549

I'm wondered why it is not working in IEs. If jQuery fails, try it in JS

document.getElementById('something').value= "";

check this fiddle

Upvotes: 0

Error on console in IE

jquery-2.0.2.js, line 1378 character 2
SCRIPT5009: '$' is undefined 
_display, line 20 character 1

enter image description here


Changed jQuery version 2.x edge

Working Fiddle

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388446

Looks like jQuery 2.0.2 has some issues with IE, use 2.0.3

If you enable debug mode in IE developer tools > script, you can see the following error

SCRIPT5: Access is denied. jquery-2.0.2.js, line 1378 character 2

$(function(){
    $("#clear1").on("click", function() {
        $("#something").val("");
    });
});

Demo: Fiddle

Upvotes: 1

Tudor Ravoiu
Tudor Ravoiu

Reputation: 2150

You are using a very new version of jQuery that isn't designed for older IE's. You should use jQuery 1.10.2

can implement it from here:
//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js

Upvotes: 0

Sridhar R
Sridhar R

Reputation: 20428

Try these

$("#something").attr('value','');

OR (Above JQuery 1.8)

$("#something").prop('value','');

Upvotes: 1

Related Questions