Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the style attribute of an element removed when its associated property declaration block becomes empty? #2306

Closed
emilio opened this issue Jan 28, 2017 · 5 comments

Comments

@emilio
Copy link
Contributor

emilio commented Jan 28, 2017

This kind of intersects between the HTML spec and CSSOM, so let me know which one is best to report it.

The following test case reports true in Firefox, and false in chromium:

<!DOCTYPE html>
<div style="color: red">one</div>
<script>
  let div = document.querySelector('div');
  div.style.color = "";
  console.log(div.hasAttribute('style'));
</script>
@emilio emilio changed the title Is the style attribute of an element removed when its associated property declaration block becomes empty Is the style attribute of an element removed when its associated property declaration block becomes empty? Jan 29, 2017
emilio added a commit to emilio/servo that referenced this issue Jan 29, 2017
emilio added a commit to emilio/servo that referenced this issue Jan 29, 2017
@annevk
Copy link
Member

annevk commented Jan 30, 2017

div.style is described by https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface. Which suggests https://drafts.csswg.org/cssom/#cssstyledeclaration describes the behavior. That currently doesn't say anything about mutating a DOM attribute, but that might very well be wrong.

@zcorpan?

@zcorpan
Copy link
Member

zcorpan commented Jan 30, 2017

https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface says

Mutating the declarations must set the style content attribute on the context object to the serialization of the declarations.

Serializing an empty declarations is "", so you set style to "".

Also see w3c/csswg-drafts#370 -- addressing that issue should make this clearer.

Test case EdgeHTML Blink Gecko WebKit
http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4846 true false true true

Seems like Chromium is the odd one out.

@annevk
Copy link
Member

annevk commented Jan 30, 2017

Yeah, I think it would be better if all the algorithms that mutate a CSSStyleDeclaration actually invoked an algorithm that took care of serializing and mutating the style content attribute, if any.

@annevk
Copy link
Member

annevk commented Jan 30, 2017

Anyway, given that this is already tracked elsewhere I think we can close this. Let me know if there are any remaining concerns.

@annevk annevk closed this as completed Jan 30, 2017
@zcorpan
Copy link
Member

zcorpan commented Jan 30, 2017

foolip pushed a commit to web-platform-tests/wpt that referenced this issue Apr 7, 2017
scheib pushed a commit to scheib/chromium that referenced this issue Apr 18, 2017
This makes us align with other browsers when, editing the style attribute, and
also with the spec, per[1]:

> Mutating the declarations must set the style content attribute on the context
> object to the serialization of the declarations

See also [2].

Note that this behavior also affects editing. I've just updated the editing
tests.

[1]: https://drafts.csswg.org/cssom/#the-elementcssinlinestyle-interface
[2]: whatwg/html#2306

BUG=686686

Review-Url: https://codereview.chromium.org/2800723002
Cr-Commit-Position: refs/heads/master@{#465181}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants