I am new to jQuery and in the learning phase. I wrote a test program in it.
<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("Button").click(function(){ $(this).parents(".ex").hide(); }); $(":button").click(function(){ $(this).parents(".ex").hide("slow"); }); }); </script> <style type="text/css"> .ex{ background-color: #e5eecc; padding: 7px; border: solid 1px #c3c3c3; } </style> </head> <body> <h3>Island Trading</h3> <div class="ex"> <input type="button" name="hid" value="Hide Me slowly"> <p> Contact: Helen Bennett</p> <p>Garden House Crowther Way</p> <p>London</p> </div> <h3>Paris spécialités</h3> <div class="ex"> <button type="button">Hide Me Quick</button> <p> Contact: Marie Bertrand</p> <p>265, Boulevard Charonne</p> <p>Paris</p> </div> </body> </html>
This works as expected. Whenever I click Hide me slowly , it hides slowly. Since the event with the ": button" selector asks to do this. as well as for Hide me Quick - the "Button" selector, it quickly hides.
But as soon as I reorder the event handling functions in the script, both of them are hidden slowly. Code change in
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(":button").click(function(){ $(this).parents(".ex").hide("slow"); }); $("Button").click(function(){ $(this).parents(".ex").hide(); }); }); </script>
My question is: I did not change the selectors, only the order is changed. For the "Button" selector, I have an event handling function that only hides and does not indicate "slow." But then he hides slowly. can you look into it and tell me why?
source share