Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shim-selected-options

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shim-selected-options

Tiny HTMLSelectElement#selectedOptions shim for IE

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by5.4%
Maintainers
1
Weekly downloads
 
Created
Source

shim-selected-options

Tiny HTMLSelectElement#selectedOptions shim for IE.

  • Can I use selectedOptions?
  • WHATWG: HTML spec
  • More conformant shim with IE8 support

Up and running

Get the package from npm:

npm install shim-selected-options --save

And simply require the module:

import "shim-selected-options"

Otherwise, plug it the old-fashioned way:

<script src="https://unpkg.com/shim-selected-options" async></script>

Caveats

While making spec-perfect shim is technically possible, it requires observing DOM subtrees to implement quirks of HTMLCollection, not to mention emulating live collection. For most cases, this solution is fine.

  • New object instead of always the same
  • NodeList instead of HTMLCollection instance
  • Static collection instead of live

See more on collections in WHATWG DOM spec.

Examples

Straightforward for single-value selects:

- let {text} = select.options[select.selectedIndex]
+ let [{text}] = select.selectedOptions

Precise typing for multiple selects:

- let opts = select.querySelectorAll(":checked") // NodeList<Element>
+ let opts = select.selectedOptions // HTMLCollection<HTMLSelectElement>

Keywords

FAQs

Package last updated on 30 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc