Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 10 years ago

#9699 closed bug (fixed)

removeAttr('style') does not consistently remove the style attribute in webkit

Reported by: azazel.private@… Owned by: Timmy Willison
Priority: high Milestone: 1.6.3
Component: attributes Version: 1.6
Keywords: Cc:
Blocked by: Blocking:

Description

  1. $('#item').css('visibility', 'hidden');
  2. $('#item').removeAttr('style'); Element still hidden...

It works fine in jQuery < 1.6

Example: http://jsfiddle.net/azproduction/hhEka/

Change History (20)

comment:1 Changed 12 years ago by Timmy Willison

Component: unfiledattributes
Priority: undecidedlow
Status: newopen

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.

comment:2 Changed 12 years ago by Timmy Willison

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:3 Changed 12 years ago by Timmy Willison

#9500 is a duplicate of this ticket.

comment:4 Changed 12 years ago by Timmy Willison

Summary: In Chrome and Safari its impossible to show visibly hidden element via removeAttrremoveAttr('style') does not consistently remove the style attribute in webkit

comment:5 Changed 12 years ago by anonymous

any workaround for removing all inline style ?

Shouldn't this work :

$("#item").prop("style", "")

?

(can't try now)

comment:6 Changed 12 years ago by Timmy Willison

Priority: lowhigh

@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.

Last edited 12 years ago by Timmy Willison (previous) (diff)

comment:7 Changed 12 years 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 12 years ago by Rick Waldron

Resolution: wontfix
Status: openclosed

comment:9 Changed 12 years ago by Timmy Willison

Milestone: 1.next1.6.3
Resolution: wontfix
Status: closedreopened

comment:10 Changed 12 years ago by Timmy Willison

Owner: set to Timmy Willison
Status: reopenedassigned

This should not have been closed.

comment:11 Changed 12 years ago by Timmy Willison

#10136 is a duplicate of this ticket.

comment:12 Changed 12 years ago by Timmy Willison

Resolution: fixed
Status: assignedclosed

Revert back to always setting the attribute to empty string before removal. Fixes #9699.

Changeset: d723942b274e3e48dac82ebde11906a4cb349415

comment:13 Changed 11 years 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 11 years ago by dmethvin

Welcome David Mark, and thanks!

comment:15 Changed 11 years 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 11 years 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 11 years 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 11 years 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 11 years ago by mikesherov

New ticket created for future hack removal: #13511

comment:20 Changed 10 years ago by ist.kein.problem@…

Just that helped for me.

$('#item').attr({ 'style' : '' });
Note: See TracTickets for help on using tickets.