Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple Example of Show/Hide Text with JQuery
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.comment {border: 1px solid red}
</style>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
// Setup the action when 'hide comments' is clicked
jQuery('#hide-comments').click(
function() {
jQuery('.comment, #hide-comments').hide();
jQuery('#show-comments').show();
}
);
// Setup the action when 'show comments' is clicked
jQuery('#show-comments').click(
function() {
jQuery('.comment, #hide-comments').show();
jQuery('#show-comments').hide();
}
);
// Hide 'show comments' when the page is loaded
jQuery('#show-comments').hide();
});
</script>
</head>
<body>
<div>
<a href='#' id='show-comments' >Show Comments</a>
<a href='#' id='hide-comments' >Hide Comments</a>
</div>
<p>Lorem ipsum dolor sit amet</p>
<p class='comment'>First Comment</p>
<p>consectetur adipisicing elit</p>
<p class='comment'>Second Comment</p>
<p>sed do eiusmod tempor incididunt</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment