Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active December 13, 2016 23:14
Show Gist options
  • Save Shelob9/e160541097a125669ebe29f5a3c7b4b0 to your computer and use it in GitHub Desktop.
Save Shelob9/e160541097a125669ebe29f5a3c7b4b0 to your computer and use it in GitHub Desktop.
<div id="main">
<div class="entry-content" id="post-1">
Hi Roy!
</div>
<div class="entry-content" id="post-2">
Hi Shawn!
</div>
</div>
<script>
jQuery(document).ready(function($) {
$( '.entry-content' ).css( 'background-color', '#fff' );
$( '#post-2' ).css( 'padding-bottom', '20px' );
});
</script>
$( '#important-link' ).on( 'click', function( event ){
//don't naviagate on click
event.preventDefault();
//do SOMETHING ELSE when link with ID #important-link is clicked
});
$( '#important-link' ).on( 'click', function( event ){
//do something when link with ID #important-link is clicked
});
<a href="#" id="hide-post-7">Hide</a>
<div id="post-7">
<!-- put post 7 here -->
</div>
<script>
jQuery(document).ready(function($) {
$( '#hide-post-7' ).on( 'click', function(event){
event.preventDefault();
$( '#post-7' ).hide();
});
});
</script>
<?php
add_action( 'wp_enqueue_scripts', function(){
wp_enqueue_script( 'jquery' );
});
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
echo '<div>';
echo '<a href="#" class="hide-post">Hide</a>';
echo '<h1>' . get_the_title() .'</h1>';
echo get_the_content();
echo '</div>';
}
}
jQuery(document).ready(function($) {
//$ is now jQuery
});
(function($) {
//$ is now jQuery
})(jQuery);
jQuery(document).ready(function($) {
$( '.hide-post' ).on( 'click', function( event ){
event.preventDefault();
$( this ).parent().hide();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment