Beginning jQuery by Jack Franklin

Beginning jQuery by Jack Franklin

Author:Jack Franklin [Franklin, Jack]
Language: eng
Format: epub, pdf
Tags: Computers, Programming Languages, JavaScript, Web, Web Programming
ISBN: 9781430249320
Publisher: Apress
Published: 2013-01-30T05:00:00+00:00


accordion.on("showParagraph", "p", function() {

paragraphs.slideUp("normal");

$(this).slideDown("normal");

});

});

This might not seem easier. In fact, your code is a bit easier, but it’s also more efficient, thanks to delegation, and it is easy to add other ways to trigger the correct paragraph sliding down. If I wanted to trigger a paragraph sliding down from another method, all I have to do is trigger the event on it. It’s simple and extensible.

Summary

You should be pretty comfortable handling events in jQuery. This is good because they are used constantly in any jQuery project, both in this book and in real life. Your accordion is now much nicer and you are able to prevent default behavior, you have a good understanding of event propagation, and you can even trigger your own events. The accordion is now better for it.

It’s still not perfect, however. In Chapter 7, we will dive further into animation, which will highlight some problems with the accordion as it stands. We’ll also explore the more complex areas of animation and, at the end of the chapter, revisit the accordion to improve it.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.