diff --git a/README.md b/README.md index ba56542..bf9b14b 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Simple usage: Advanced usage: $('#my_textarea').simplyCountable({ - counter: '#counter', + counter: '#counter', //or $('#counter') countType: 'characters', maxCount: 140, strictMax: false, @@ -30,7 +30,7 @@ Advanced usage: ## Options -* `counter` - A jQuery selector to match the 'counter' element. Defaults to `#counter`. +* `counter` - A jQuery selector or jQuery object to match the 'counter' element. Defaults to `#counter`. * `countType` - Select whether to count `characters` or `words`. Defaults to `characters`. * `maxCount` - The maximum character (or word) count of the text input or textarea. Defaults to `140`. * `strictMax` - Prevents the user from being able to exceed the `maxCount`. Defaults to `false`. diff --git a/jquery.simplyCountable.js b/jquery.simplyCountable.js index 7c1d577..bc384da 100644 --- a/jquery.simplyCountable.js +++ b/jquery.simplyCountable.js @@ -34,7 +34,18 @@ return $(this).each(function(){ var countable = $(this); - var counter = $(options.counter); + var counter; + + if (typeof(options.counter) == 'string'){ + counter = $(options.counter); + } + else if (options.counter instanceof jQuery){ + counter = options.counter; + } + else { + throw new Error("The counter option must be a jQuery selector or a jQuery object."); + } + if (!counter.length) { return false; } var countCheck = function(){