jquery - image not sliding in ruby on rails -
i using jquery cycle lite plugin making image slide in rails app. not working. can tell me problem in code?
<html> <head> <title>healthcare</title> <%= stylesheet_link_tag "ehrms", :media => "all" %> <script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script> <script type='text/javascript' src='script.js'> $('#mar').cycle({ delay: 2000, speed: 500, before: onbefore }); </script> </head> </html> #mar division images slide.
the javascript code running page loads, page may not ready run scripts yet (the dom may not have been initialized, #mar element may not exist yet).
typically want wrap such code in jquery ready() function, so:
<script type='text/javascript' src='script.js'></script> <script type='text/javascript'> $(document).ready(function(){ $('#mar').cycle({ delay: 2000, speed: 500, before: onbefore }); }); </script> see ready() documentation more details.
update
you may have additional problem in code, <script> tag has both src attribute (src='script.js') has contents between <script>...</script> tags. according this question, that's not valid , body of <script> tags ignored. try breaking out separate <script> tag. i've updated code snippet above example of how that.
Comments
Post a Comment