<script type="text/javascript">
$("document").ready(function() {
$("button").click(function() {
$("[src$='.jpg']").slideToggle(1000);
})
}
)
</script>
<img src="http://images2.wikia.nocookie.net/__cb20101129232634/callofduty/images/2/2e/Pripyat.jpg">
<button>Click me</button>
is same like
<script type="text/javascript">
$("document").ready(function() {
$("button").click(function() {
$("img [src$='.jpg']").toggle(1000);
})
}
)
</script>
<img src="http://images2.wikia.nocookie.net/__cb20101129232634/callofduty/images/2/2e/Pripyat.jpg">
<button>Click me</button>
So is there really any difference?
It should be pointed out however that there is a difference in the animation, albeit a small one: .toggle()
will slide the element from the top left corner, whereas .slideToggle
will slide it from top to bottom.
You can see an example for both effects on this fiddle.
.toggle():
Display or hide the matched elements.
.slideToggle():
Display or hide the matched elements with a sliding motion.
With your usage, you will not see a difference.
The jQuery documentation site is very good and should be the first place to look for this kind of question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With