Skip to content

Instantly share code, notes, and snippets.

@whyisjake
Created February 8, 2013 04:23
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 whyisjake/4736577 to your computer and use it in GitHub Desktop.
Save whyisjake/4736577 to your computer and use it in GitHub Desktop.
Any ideas on how to factor this? I can change the IDs or add data attributes if needed.
jQuery(document).ready(function(){
jQuery('#link-js-step-1').click(function() {
console.log('Clicked');
googletag.pubads().refresh();
_gaq.push(['_trackPageview']);
jQuery('#js-step-1').slideDown();
jQuery('#js-step-2').slideUp();
jQuery('#js-step-3').slideUp();
jQuery('#js-step-4').slideUp();
jQuery('#js-step-5').slideUp();
});
jQuery('#link-js-step-2').click(function() {
console.log('Clicked');
googletag.pubads().refresh();
_gaq.push(['_trackPageview']);
jQuery('#js-step-2').slideDown();
jQuery('#js-step-1').slideUp();
jQuery('#js-step-3').slideUp();
jQuery('#js-step-4').slideUp();
jQuery('#js-step-5').slideUp();
});
jQuery('#link-js-step-3').click(function() {
console.log('Clicked');
googletag.pubads().refresh();
_gaq.push(['_trackPageview']);
jQuery('#js-step-3').slideDown();
jQuery('#js-step-1').slideUp();
jQuery('#js-step-2').slideUp();
jQuery('#js-step-4').slideUp();
jQuery('#js-step-5').slideUp();
});
jQuery('#link-js-step-4').click(function() {
console.log('Clicked');
googletag.pubads().refresh();
_gaq.push(['_trackPageview']);
jQuery('#js-step-4').slideDown();
jQuery('#js-step-1').slideUp();
jQuery('#js-step-2').slideUp();
jQuery('#js-step-3').slideUp();
jQuery('#js-step-5').slideUp();
});
jQuery('#link-js-step-5').click(function() {
console.log('Clicked');
googletag.pubads().refresh();
_gaq.push(['_trackPageview']);
jQuery('#js-step-5').slideDown();
jQuery('#js-step-1').slideUp();
jQuery('#js-step-2').slideUp();
jQuery('#js-step-3').slideUp();
jQuery('#js-step-4').slideUp();
});
});
@colegeissinger
Copy link

Here ya go! https://gist.github.com/colegeissinger/4741029 Check it out on Codepen to see it work and make sure it's your expected results.. http://codepen.io/colegeissinger/pen/qdvGB

@whyisjake
Copy link
Author

jQuery(document).ready(function(){
    jQuery('#tabs div').click(function() {
        id = jQuery(this).attr('id');
        googletag.pubads().refresh();
        _gaq.push(['_trackPageview']);
        jQuery('.tab-content div#js-' + id).slideDown();
        jQuery('.tab-content div:not(#js-' + id + ')').slideUp();
    });
});

Thanks @colegeissinger, got it with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment