Advertisement
Guest User

Untitled

a guest
Nov 6th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <button id="b1" type="button">Show Spoiler</button>
  7. <p id="p1" style="display:none"> This is a damn paragraph.</p>
  8.  
  9. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  10. <script type="text/javascript" src="js/script.js"></script>
  11. </body>
  12. </html>
  13.  
  14. function bindEvent(element, eventName, eventHandler) {
  15. var el = $(element)[0];
  16. if (el.addEventListener) {
  17. el.addEventListener(eventName, eventHandler, false)
  18. } else if (el.attachEvent) {
  19. el.attachEvent('on'+eventName, eventHandler);
  20. }
  21. }
  22. bindEvent('#b1', 'click', function() {
  23. $('#p1').toggle('blind');
  24. if ($('#b1').text() == 'Show Spoiler') {
  25. $('#b1').text('Hide Spoiler');
  26. } else if ($('#b1').text() == 'Hide Spoiler') {
  27. $('#b1').text('Show Spoiler');
  28. }
  29.  
  30. });
  31.  
  32. var $b1 = $('#b1')
  33. , $p1 = $('#p1')
  34. , hideText = 'Hide Spoiler'
  35. , showText = 'Show Spoiler'
  36.  
  37. $b1.on('click',function() {
  38. var text = $b1.text()
  39. , newText = text === showText ? hideText : showText
  40. $p1.toggle('blind')
  41. $b1.text(newText)
  42. })
  43.  
  44. $('.spoiler-trigger').on('click',function() {
  45. var $this = $(this)
  46. , $thisSpoiler = $this.siblings('.spoiler').eq(0)
  47. , text = $this.text()
  48. , newText = text === showText ? hideText : showText
  49. $thisSpoiler.toggle('blind')
  50. $this.text(newText)
  51. })
  52.  
  53. $("#b1").click(function () {
  54. $("#p1").toggle('slow');
  55. });​
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement