$(function(){
  $('.comment').keyup(function(ev){
    var textarea = $(this);
    var id = textarea.attr('id');
  })
});

The context 'this' in jQuery callbacks is always a DOMElement and always
corresponds to the element to which the event is bound.

You could also get it from ev.target in this case, but they may not always
be the same (if the event has bubbled up to a parent element that has the
bound event). For example

<div><textarea></textarea></div>

If you bind a keyup to the div, then press a key in the textarea, 'this'
will be the div, event.target will be the textarea.

- Richard

On Wed, Jun 11, 2008 at 8:42 AM, iam_peter <[EMAIL PROTECTED]> wrote:

>
> hello,
>
> folowing problem:
>
> i have to (or more) textareas look like this
>
> <textarea class="comment" id="comment1" rows="6" cols="50"></
> textarea><br />
> <textarea class="comment" id="comment2" rows="6" cols="50"></
> textarea><br />
>
> you see the clas of both is comment so i can combine more textareas to
> one keyup (later) and the id is different (this is important for
> another thing).
>
> i call this function to get the event when keyup on one of the
> textareas with the class comment
>
> $(function(){
>        $('.comment').keyup(function(){
>                limitChars('comment1,comment2', 20, 'charlimitinfo');
>        })
> });
>
> now my question is: how can i get the id on wich the keyup was done,
> f.e. when i type something into textarea id="comment1" then i want to
> know the id?
>
> possible solution is this one, but i can not make a class of
> textfareas this one is just for 2 and every time i will add a textarea
> i have to add a newline of code here:
>
> $(function(){
>        $('#comment1').keyup(function(){
>                limitChars('comment1,comment2', 20, 'charlimitinfo');
>        })
>        $('#comment2').keyup(function(){
>                limitChars('comment1,comment2', 20, 'charlimitinfo');
>        })
> });
>
> thanks
>

Reply via email to