Socket
Socket
Sign inDemoInstall

stimulus

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stimulus

Stimulus JavaScript framework


Version published
Weekly downloads
22K
decreased by-80.76%
Maintainers
2
Weekly downloads
 
Created

What is stimulus?

Stimulus is a JavaScript framework that enhances the behavior of HTML elements by connecting them to JavaScript controllers. It is designed to work with the HTML you already have, making it easy to add interactivity to your web applications without the need for a complex setup.

What are stimulus's main functionalities?

Controller Initialization

This feature allows you to initialize a Stimulus controller and connect it to HTML elements. The controller listens for events (like a button click) and executes the corresponding JavaScript function.

```html
<!-- HTML -->
<div data-controller="example">
  <button data-action="click->example#sayHello">Click me</button>
</div>

<!-- JavaScript -->
import { Controller } from "stimulus";

export default class extends Controller {
  sayHello() {
    alert("Hello, Stimulus!");
  }
}
```

Data Attributes

Stimulus uses data attributes to pass information from HTML to JavaScript. This example demonstrates how to use data attributes to store and retrieve data within a controller.

```html
<!-- HTML -->
<div data-controller="example" data-example-name="Stimulus">
  <button data-action="click->example#greet">Greet</button>
</div>

<!-- JavaScript -->
import { Controller } from "stimulus";

export default class extends Controller {
  greet() {
    const name = this.data.get("name");
    alert(`Hello, ${name}!`);
  }
}
```

Targets

Targets in Stimulus allow you to easily reference specific elements within your controller. This example shows how to use targets to get the value of an input field and use it in a function.

```html
<!-- HTML -->
<div data-controller="example">
  <input data-example-target="name" type="text" placeholder="Enter your name">
  <button data-action="click->example#greet">Greet</button>
</div>

<!-- JavaScript -->
import { Controller } from "stimulus";

export default class extends Controller {
  static targets = ["name"];

  greet() {
    const name = this.nameTarget.value;
    alert(`Hello, ${name}!`);
  }
}
```

Other packages similar to stimulus

FAQs

Package last updated on 18 Jan 2018

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc