Advertisement
saasbook

simple_jquery_example.js

Apr 6th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. RP = {};
  2. RP.setup = function() {
  3. // construct new DOM elements
  4. $('<label for="filter" class="explanation">' +
  5. 'Restrict to movies suitable for children' +
  6. '</label>' +
  7. '<input type="checkbox" id="filter"/>'
  8. ).insertBefore('#movies').change(RP.filter_adult);
  9. };
  10. RP.filter_adult = function () {
  11. // 'this' is element that received event (checkbox)
  12. if ($(this).is(':checked')) {
  13. $('#movies tbody tr').each(RP.hide_if_adult_row);
  14. } else {
  15. $('#movies tbody tr').show();
  16. };
  17. };
  18. RP.hide_if_adult_row = function() {
  19. var rating = this.find('td:nth-child(2)').text();
  20. if (! /^G|PG$/i.test(rating) {
  21. this.hide();
  22. };
  23. };
  24. $(RP.setup); // when document ready, run setup code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement