From the course: jQuery: Creating Plugins

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Writing a new, useful plugin

Solution: Writing a new, useful plugin - jQuery Tutorial

From the course: jQuery: Creating Plugins

Start my 1-month free trial

Solution: Writing a new, useful plugin

- Let's take a look at my solution to this plug-in challenge. You can find it in chapter two and in the folder O2O5. So loading this file up in the browser, if I start typing in any of these fields you can see that the limit fields all update. This is great. Let's switch over to the HTML and take a look. So here we are, I've broken the plug-in into its own file called jquey.show_char_limit.js. This jquery.pluginname.js is a very common pattern you'll see in jQuery plug-ins, but of course, you can name it anything you like. So here I'm just using a selector that picks out all text areas and this underscore text field class, which is how I've selected the one input field. Currently it's the only one that has this, but if there were more it would cover all of them. And then I'm invoking this show_char_limit method. And just to make sure it's clear that not only does the plug-in work, chaining also works, let's add on a method here. We'll add on our old friend the CSS method. This time…

Contents