saasbook

simple_jquery_example.js

Jul 11th, 2012
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. RP = {
  2. 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. 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. hide_if_adult_row: function() {
  19. if (! /^G|PG$/i.test($(this).find('td:nth-child(2)').text())) {
  20. $(this).hide();
  21. }
  22. }
  23. }
  24. $(RP.setup); // when document ready, run setup code
Advertisement
Add Comment
Please, Sign In to add comment