Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RP = {};
- RP.setup = function() {
- // construct new DOM elements
- $('<label for="filter" class="explanation">' +
- 'Restrict to movies suitable for children' +
- '</label>' +
- '<input type="checkbox" id="filter"/>'
- ).insertBefore('#movies').change(RP.filter_adult);
- };
- RP.filter_adult = function () {
- // 'this' is element that received event (checkbox)
- if ($(this).is(':checked')) {
- $('#movies tbody tr').each(RP.hide_if_adult_row);
- } else {
- $('#movies tbody tr').show();
- };
- };
- RP.hide_if_adult_row = function() {
- var rating = this.find('td:nth-child(2)').text();
- if (! /^G|PG$/i.test(rating) {
- this.hide();
- };
- };
- $(RP.setup); // when document ready, run setup code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement