A discussion today led to me sending out an email to all the developers at work today, which given the amount of campaigning for jQuery I've done at the company, I had hoped would'nt have been necessary. But it was.
Basically a co-worker had asked me for some assistance with some HTML/CSS. Unfortunately this led to me looking at his code and discovering an abundance of javascript events specified directly within the HTML.
<div id="MyElement" onclick="javascript: myFunction();">Click Me!</div>
As I mention, we've adopted jQuery quite widely throughout our products, so I pointed out that it would be much easier for everyone to follow, and easier to take advantage of jQuery's special events and event delegation functions if the events were bound in the $(document).ready() function for that page. What's more, we know the separating style and markup is important, keeping javascript and the markup separate is also important. By keeping them apart it makes it easier to split the javascript off into a separate file (much easier to minify AND it's cached!).
So as I say this is just a quick blog post in case anyone else is unsure about where the best place to specify javascript events are. In my opinion, not the HTML!
As part of what I aim to be a regular series I'm covering great jQuery articles and plugins I've seen over the previous week. I aim to post this "around" Friday every week, this week may be a little light as I've only been keeping track of articles I've seen for the last few days.
As I say, next weeks should have a little more to it. I aim to be a lot more active on this site this year and going forwards, next stage is to implement the article system to display more in-depth articles. In the mean time I shall endeavour to keep blogging.
This would be my first blog post in over a year, but I've been busy working on the new version of this site. Generally I'm much happier with this design than the previous, but it's extremely likely you never saw the previous design, so that's fine anyway.
I hope to blog much more frequently now, probably covering all sorts of things. In addition once I have the article system online I'll be posting more in-depth programming articles and tutorials. Before that all starts though, as part of my job I made a blog post of how to pass Table Variable Value Parameters to C#, It's a great technique we've started using that's loads faster than XML, and much safer in my opinion. It can be found at the company website, Passing Table Value parameters to Stored Procedures from C#.