Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created February 2, 2018 15:02
Show Gist options
  • Save jgaskins/6c560830ec482293318e23da957fefad to your computer and use it in GitHub Desktop.
Save jgaskins/6c560830ec482293318e23da957fefad to your computer and use it in GitHub Desktop.
Stimulus vs jQuery
<div class="hello" data-controller="hello">
<input id="hello-name" data-target="hello.name" type="text" />
<button id="hello-greet" data-action="click->hello#greet">Greet</button>
<span id="hello-output" data-target="hello.output"></span>
</div>
import $ from 'jquery';
$('#hello-greet').click(() => {
$('#hello-output').text(`Hello ${$('#hello-name').val()}!`);
});
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ['name', 'output']
greet = () => {
this.outputTarget.textContent = `Hello ${this.nameTarget.value}!`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment