Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active July 10, 2016 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpataki/36d467f72129e4c6177ce13d8f61c032 to your computer and use it in GitHub Desktop.
Save danielpataki/36d467f72129e4c6177ce13d8f61c032 to your computer and use it in GitHub Desktop.
Getting Started With jQuery
jQuery('.post .entry-title').addClass('better-entry-title')
jQuery('#masthead .site-description').append( ", I'm also on WPMU DEV" )
jQuery('.post:first').attr('id');
jQuery('.post:first').attr('id', 'the-first-post');
jQuery('.post .entry-title a').css({
background: '#000000',
color: '#ffffff',
padding: '11px',
borderBottom: '5px solid #F8E71C'
})
jQuery('.widget-title:eq(0)').css({ background: 'red' });
jQuery(document).on( 'dblclick', '#masthead', function(){
jQuery('#masthead .site-description').text( 'You have found my double click easter egg!' );
});
<?php
add_action( 'wp_enqueue_scripts', 'jquery_test_assets' );
function jquery_test_assets() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css' );
wp_enqueue_script( 'jquery-test', get_stylesheet_directory_uri() . '/scripts.js', array('jquery'), '1.0.0', true );
}
jQuery('.widget-title:gt(2)').css({ background: 'red' });
jQuery('aside').children().has('.widget-title').css({ background: 'red' });
// treats string as HTML outputting a an actual link
jQuery('#masthead .site-description').html( 'Read me on <a href="http://premium.wpmudev.org/blog/author/danielpataki">WPMU DEV</a> as well' )
// trets string as text, outputs the string as-is
jQuery('#masthead .site-description').text( 'Read me on <a href="http://premium.wpmudev.org/blog/author/danielpataki">WPMU DEV</a> as well' )
jQuery('.widget-title').css({ background: 'red' });
jQuery('.widget:not(.widget_categories) .widget-title').css({ background: 'red' });
jQuery('#masthead').css({ background: 'red' });
/*
Theme Name: Jquery Test Theme
Description: A theme based on Twenty Sixteen for testing our jQuery prowess
Author: Daniel Pataki
Author URI: http://danielpataki.com
Template: twentysixteen
Version: 1.0.0
*/
jQuery('.widget').prepend( '<span class="toggle-widget">toggle</span>' )
jQuery( document ).on( 'click', '.toggle-widget', function() {
jQuery(this).parent().find('*').not('.toggle-widget, .widget-title').toggle();
})
jQuery('aside').children().find('h2').css({ background: 'red' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment