Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- </head>
- <body>
- <button id="b1" type="button">Show Spoiler</button>
- <p id="p1" style="display:none"> This is a damn paragraph.</p>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
- <script type="text/javascript" src="js/script.js"></script>
- </body>
- </html>
- function bindEvent(element, eventName, eventHandler) {
- var el = $(element)[0];
- if (el.addEventListener) {
- el.addEventListener(eventName, eventHandler, false)
- } else if (el.attachEvent) {
- el.attachEvent('on'+eventName, eventHandler);
- }
- }
- bindEvent('#b1', 'click', function() {
- $('#p1').toggle('blind');
- if ($('#b1').text() == 'Show Spoiler') {
- $('#b1').text('Hide Spoiler');
- } else if ($('#b1').text() == 'Hide Spoiler') {
- $('#b1').text('Show Spoiler');
- }
- });
- var $b1 = $('#b1')
- , $p1 = $('#p1')
- , hideText = 'Hide Spoiler'
- , showText = 'Show Spoiler'
- $b1.on('click',function() {
- var text = $b1.text()
- , newText = text === showText ? hideText : showText
- $p1.toggle('blind')
- $b1.text(newText)
- })
- $('.spoiler-trigger').on('click',function() {
- var $this = $(this)
- , $thisSpoiler = $this.siblings('.spoiler').eq(0)
- , text = $this.text()
- , newText = text === showText ? hideText : showText
- $thisSpoiler.toggle('blind')
- $this.text(newText)
- })
- $("#b1").click(function () {
- $("#p1").toggle('slow');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement