Advanced jQuery
I went through advanced jQuery today as the last part of the web fundamentals course. On paper, dynamic content is simple; they're elements that are created after the page is loaded. You use the .append() function and whatever function is in the parameter is what will be executed after a certain event occurs. Now add in .on() which is a way to add event handlers. Event handlers are code that executes a function when an event happens (click a button, hover or something etc.). Make the selector as specific as possible so that the server doesn't take too much time finding all the elements.
Now for callbacks. Callbacks are just functions that causes other functions run after a certain event. Sound like the .on() function? It is similar, but callbacks allow for more precise coding. Write out a callback function outside the scope of $(document).ready, (this is to allow the callback to exist anywhere on jQuery) and plug whatever you dub the callback function into your jQuery scripts.
Anyways, it was pretty tough but I had a breakthrough late in the day. I kept thinking append() and on() methods as really daunting tasks but once I started to little stuff by little stuff, it's essentially creating something in html but within the parameters of append. One thing that took me a while to get a hang of is that when you write .append('<div>' + [insert html elements] '</div'), you can STILL id/class whatever HTML elements you are putting in. Which makes customizing the element with CSS a breeze.
I think the hardest part about jQuery is learning which methods can stack with other methods so you don't have to write a lot of code. I guess that comes with practice and doing more problems. jQuery is super useful for the front-end side of things, and there are so many methods has been developed and I'm pretty sure will there will be more cool animations developed later!
I think the hardest part about jQuery is learning which methods can stack with other methods so you don't have to write a lot of code. I guess that comes with practice and doing more problems. jQuery is super useful for the front-end side of things, and there are so many methods has been developed and I'm pretty sure will there will be more cool animations developed later!
No comments:
Post a Comment