TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Best way to echo some js (http://www.talkphp.com/general/5007-best-way-echo-some-js.html)

Jmz 10-07-2009 06:52 PM

Best way to echo some js
 
I have an if statement that will echo some javascript if certain things are true.

I'm currently writing it as:

PHP Code:

<?php
if($x=1){
?>
        <script type="text/javascript">
            $(document).ready(function(){
                $('.boxgrid.captionfull').hover(function(){
                    $(".cover", this).stop().animate({top:'30px'},{queue:false,duration:160});
                }, function() {
                    $(".cover", this).stop().animate({top:'150px'},{queue:false,duration:160});
                });
            });
        </script>
<?php
}
?>

Obviously that's not my real if, it's just to give you an idea.

I'm sure there must be a better way to do it than this?

ETbyrne 10-07-2009 08:00 PM

Looks OK to me... You may want to consider using PHP's short tags for this too:

PHP Code:

<?php if($x==1): ?>

    javascript...

<?php endif; ?>



All times are GMT. The time now is 11:07 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0