Reputation: 15158
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
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
Reputation: 57105
Error on console in IE
jquery-2.0.2.js, line 1378 character 2
SCRIPT5009: '$' is undefined
_display, line 20 character 1
Upvotes: 1
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
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
Reputation: 20428
Try these
$("#something").attr('value','');
OR (Above JQuery 1.8)
$("#something").prop('value','');
Upvotes: 1