Ticket #9699 (closed bug: fixed)
removeAttr('style') does not consistently remove the style attribute in webkit
| Reported by: | azazel.private@… | Owned by: | timmywil |
|---|---|---|---|
| Priority: | high | Milestone: | 1.6.3 |
| Component: | attributes | Version: | 1.6 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
- $('#item').css('visibility', 'hidden');
- $('#item').removeAttr('style'); Element still hidden...
It works fine in jQuery < 1.6
Change History
comment:1 Changed 23 months ago by timmywil
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to attributes
comment:2 Changed 23 months ago by timmywil
This seems to be a webkit bug. removeAttribute does not consistently remove the style attribute at all times.
@azazel In the meantime, the recommended way to reset a style is to set it to empty string with css:
$('#item').css('visibility', '')
comment:4 Changed 23 months ago by timmywil
- Summary changed from In Chrome and Safari its impossible to show visibly hidden element via removeAttr to removeAttr('style') does not consistently remove the style attribute in webkit
comment:5 Changed 23 months ago by anonymous
any workaround for removing all inline style ?
Shouldn't this work :
$("#item").prop("style", "")
?
(can't try now)
comment:6 Changed 23 months ago by timmywil
- Priority changed from low to high
@anonymous: that would be bad. The style property is an object which contains all styles, including defaults, for the element. You could do .attr('style', ) or elem.style.cssText = ; or set each style individually with the css method as shown above.
comment:7 Changed 23 months ago by anonymous
I found that
.attr('style', '')
works good.
You're right, I forgot about the cssText subproperty... Maybe it would be more reliable/cross-browser if we used this.
comment:8 Changed 23 months ago by rwaldron
- Status changed from open to closed
- Resolution set to wontfix
comment:9 Changed 21 months ago by timmywil
- Status changed from closed to reopened
- Resolution wontfix deleted
- Milestone changed from 1.next to 1.6.3
comment:10 Changed 21 months ago by timmywil
- Owner set to timmywil
- Status changed from reopened to assigned
This should not have been closed.
comment:11 Changed 21 months ago by timmywil
#10136 is a duplicate of this ticket.
comment:12 Changed 21 months ago by timmywil
- Status changed from assigned to closed
- Resolution set to fixed
Revert back to always setting the attribute to empty string before removal. Fixes #9699.
Changeset: d723942b274e3e48dac82ebde11906a4cb349415
comment:13 Changed 13 months ago by jQuery: eternally clueless
Do you idiots not get it? The style attribute is never being set. The visibility property of the style object is being set. Of course removeAttribute does nothing. The only reason this worked before was because of your broken attr implementation that mucked with properties.
comment:14 Changed 13 months ago by dmethvin
Welcome David Mark, and thanks!
comment:15 Changed 12 months ago by iamchriswick
Hi,
I have a
<span style="display: none; ">
that is generated in my code, and I cant figure out why "display: none;" is set.
I have tried using:
$('span').removeAttr('style');
and
$('span').attr('style', '')
...but none of them are working.
Some how
$('span').removeAttr(style);
is working, but of cource that give an error due to the missing around style.
Any suggestions?
comment:16 Changed 7 months ago by GU Yiling
Hi guys,
Here's a good news: WebKit might fix the related bug ( https://bugs.webkit.org/show_bug.cgi?id=99295) soon and jQuery can get rid of the current hack in the near future!
comment:17 Changed 3 months ago by anonymous
https://bugs.webkit.org/show_bug.cgi?id=99295 was fixed on 2012-11-06. Can this hack be removed?
comment:18 Changed 3 months ago by mikesherov
At some point in the future, yes, we can remove the hack. Unfortunately, there's still a lot of old version of webkit floating around out there who don't have this fix yet.
comment:19 Changed 3 months ago by mikesherov
New ticket created for future hack removal: #13511
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

The style attribute is not always getting removed, but this is strangely inconsistent. It does work sometimes and it does work when done from the console.