Skip to content

Should onselectstart and onselectionchange have content attributes or just IDL attributes? #351

Open

Description

@josepharhar

The spec currently lists IDL attributes for onselectstart and onselectionchange here: https://w3c.github.io/selection-api/#extensions-to-globaleventhandlers

Someone found the onselectionchange content attribute is not currently interoperable between browsers. Consider the following:

<div id=parent onselectionchange="console.log('parent onselectionchange')">
  <input onselectionchange="console.log('input onselectionchange')">
</div>

Firefox and Safari will attach selectionchange event listeners for both elements, but chrome does neither. I'd be happy to implement this in chrome if the spec is updated to explicitly say that we should have global onselectionchange content attributes in addition to IDL attributes.

I suspect that onselectstart has the same interop issue right now.

Activity

  1. josepharhar commented on Sep 8, 2025

    @josepharhar
    Author

    @rniwa do you have any thoughts on this?

  2. masayuki-nakano commented on Sep 9, 2025

    @masayuki-nakano

    I think Chrome should have it. on* global attribute is the only way to check whether the browser supports the event. Although nobody needs to check that for selectionchange, but the consistency must be good.

    And the partial interface is GlobalEventHandlers which is explicitly included by HTMLElement.

  3. annevk commented on Sep 9, 2025

    @annevk
    Member

    Creating a partial interface of GlobalEventHandlers is not sufficient to add new HTML attributes though.

    Having them as content attributes is probably good for consistency, but what that would require is a change to the HTML standard. Add the attributes there and then remove the partial interface here. (In theory you could also define the content attributes separately here, but I don't think that's good. We want HTML to be defined in a single place.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions