I created a jQuery plugin that manage the input content (max chars, preg match,…). And I would like to use it like this:
$("form textarea.count-chars").smartInput({
counterDiv: "#" + $(this).attr("id") + "-chars-left",
maxChars: 128
});
This means, the plugin takes all the textareas with a class “count-chars” and display a countdown chars in a div block with the same id as the corresponding textarea + “-chars-left”. And here the problem is…
console.log revealed that $(this).attr(“id”) refer to undefined !!!
So: How can I use the attributes of an input (for example) as a plugin parameter?
Here is the plugin: http://github.com/hassinus/smartInput
Thanks in advance.
Only thing I can think of right now is to use
.each()