Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ninnypants/1318769 to your computer and use it in GitHub Desktop.
Save ninnypants/1318769 to your computer and use it in GitHub Desktop.
Looking for an easy way to load a php array into some jQuery... Any ideas on how to simplify this?
<script>
post_ids = <?php echo json_encode(array(185,4,171)); ?>;
$(document).ready(function(){
/* Put your jQuery here */
$('.post-'+post_ids[1]).hide();
$('.post-'+post_ids[2]).hide();
$('.click'+post_ids[0]).addClass('active');
$('.click185').click(function() {
$('.post-'+post_ids[2]+',.post-'+post_ids[2]).hide();
$('.post-'+post_ids[0]).show();
$('.click'+post_ids[0]).addClass('active');
$('.click'+post_ids[2]+', .click'+post_ids[1]).removeClass('active');
});
$('.click4').click(function() {
$('.post-'+post_ids[0]+',.post-'+post_ids[2]).hide();
$('.post-'+post_ids[1]).show();
$('.click'+post_ids[1]).addClass('active');
$('.click'+post_ids[2]+', .click'+post_ids[0]).removeClass('active');
});
$('.click'+post_ids[2]).click(function() {
$('.post-'+post_ids[2]).show();
$('.post-'+post_ids[1]+',.post-'+post_ids[0]).hide();
$('.click'+post_ids[2]).addClass('active');
$('.click'+post_ids[1]+', .click'+post_ids[0]).removeClass('active');
});
})
</script>
@whyisjake
Copy link

Ty, this is awesome, thanks again.

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