-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ty, this is awesome, thanks again.