Jquery show, hide function does not work -


jquery find function hide , show not work, wrong?

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>    <script>         $('div').hover(function() {            $(this).find('.delete').show();         }, function() {            $(this).find('.delete').hide();         });   </script>   <div>     blah     <span class="delete">delete</span> </div> 

add document ready function script , work

  <script>       $(document).ready(function(){         $('div').hover(function() {            $(this).find('.delete').show();         }, function() {            $(this).find('.delete').hide();         });       });   </script> 

explanation:

you binding hover function div before div exists.
using document ready function, binding of function takes place when div available


Comments

Popular posts from this blog

Unlimited choices in BASH case statement -

Redirect to a HTTPS version using .htaccess -

javascript - jQuery: Add class depending on URL in the best way -