Created
February 2, 2018 15:02
-
-
Save jgaskins/6c560830ec482293318e23da957fefad to your computer and use it in GitHub Desktop.
Stimulus vs jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ from 'jquery'; | |
$('#hello-greet').click(() => { | |
$('#hello-output').text(`Hello ${$('#hello-name').val()}!`); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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