I’am doing some form validation and noticed that Internet Explorer don’t works correctly (as always). If I attach some text and CSS into a div-element and delete it again (when the input is ok) the Explorer doesn’t correct the display again. I mean the text gets deleted, but there still remains a blank row (as if there is br-element). I’ve checked the source-code and the CSS was deleted correctly, but the display isn’t correct. Why?
Other browsers have no problems.
if(bla)
{
$("div[bez='avz_kw_err']").eq(index).html("Mindestens 3 Zeichen");
$("div[bez='avz_kw_err']").eq(index).attr("style","color:red; font-size:12px; line-height:12px; position:relative; top:5px; left:25px;");
}
else
{
$("div[bez='avz_kw_err']").eq(index).html("");
$("div[bez='avz_kw_err']").eq(index).attr("")
}
Don’t use “.attr()” to set the style property with jQuery 1.6 or newer. Use “.prop()” instead:
The “style” property is a property. IE is very picky about the difference. Use “.prop()” for anything that, when dealing directly with the DOM element un-wrapped by jQuery, you’d treat as an ordinary property of the object: “name”, “id”, “className”, “tagName”, etc.
edit because I’m slow this evening — that said – and it’s all true – the “style” property in particular is not a string-valued property. It’s an object in its own right, and setting it to “” doesn’t really make sense (to Firefox or IE). But you can zap all the CSS properties:
edit again — hey gang stop upvoting me until I figure out the right answer – this may not work in IE …
edit boy is IE weird … OK in IE8 this works:
It’s apparently important to use
nullinstead of the empty string; at some point setting something to the empty string caused IE to seize up and spin the CPU for a few seconds.