Created
February 12, 2019 23:40
-
-
Save matticustard/f3be8349d443365e8025ceb3f2cf52a1 to your computer and use it in GitHub Desktop.
Simple example: Show or hide secondary paragraph by clicking a link (requires jQuery).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
Your visible text. | |
</p> | |
<a id="toggle_text" href="#!">More...</a> | |
<p id="hidden_text" style="display: none;"> | |
Your hidden text. | |
</p> | |
<script> | |
// wait for document to be fully rendered | |
$('document').ready(function() { | |
// capture click event | |
$('body').on('click','#toggle_text',function(e) { | |
console.log('ok'); | |
// prevent default link clicking action | |
e.preventDefault(); | |
// define the target object you want to control | |
var target = $('#hidden_text'); | |
var link = $('#toggle_text'); | |
// toggle the visibility and link text | |
if (target.is(":visible")) { | |
// hides target and sets link text to "More..." | |
target.hide(); | |
link.html('More...'); | |
} else { | |
// shows target and sets link text to "Hide..." | |
target.show(); | |
link.html('Hide...'); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment