Skip to content

Instantly share code, notes, and snippets.

@Yago
Created June 16, 2016 06:27
Show Gist options
  • Save Yago/f25c613b86a592cc519e677538ba7972 to your computer and use it in GitHub Desktop.
Save Yago/f25c613b86a592cc519e677538ba7972 to your computer and use it in GitHub Desktop.
Classic website - JavaScript usage
import $ from 'jquery';
const format = () => {
$('.btn').each((i, e) => {
const that = $(e);
that.addClass('btn-danger');
});
};
export default format;
...
<script src="//code.jquery.com/jquery-2.2.4.min.js" crossorigin="anonymous"></script>
<script src="/build/js/bundle.js"></script>
...
import $ from 'jquery';
import format from './format';
import { toggleColor, toggleVisible } from './toggle';
$(document).on('ready', () => {
format();
toggleColor();
toggleVisible();
});
import $ from 'jquery';
export const toggleColor = () => {
if ($('#my-button').length > 0) {
$('#my-button').on('click', e => {
const that = $(e.currentTarget);
that.next().toggleClass('text-danger text-success');
});
}
};
export const toggleVisible = () => {
if ($('#my-button').length > 0) {
$('#my-button').on('click', e => {
const that = $(e.currentTarget);
that.next().toggleClass('hidden');
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment