You can use the jQuery method attr() to get the id attribute of the element.

$(this).attr('id');

However, since 'this' is the element and there is a DOM property
exposing the id you can get the id from the a tag like this.

this.id;

So with that knowledge here is how the click hander would look.

$(function(){
  $(this).find('a.reminder').click(function(){
      $('#div_' + this.id).toggle();
      this.blur()
      return false;
  });//end click
});

I also just used the DOM method blur instead of the jQuery blur()
method (which actually just calls the DOM method blur()). Since you
have the DOM element and not doing anything else with it, it makes
more sense to just use the DOM method. Saving on typing too. :)

You can also write your selector like this:

$('a.reminder', this).click(function() {

The second parameter is the scope in which jQuery should run the selector.

--
Brandon Aaron


On 4/20/07, Shelane Enos <[EMAIL PROTECTED]> wrote:

I apologize if this solution is posted, but I searched and trying to get
through hundreds of results is a bit painful.

So I have these titles: Create Reminder, Create Hold Status, Change State.
I want to bind a click event to all of them which will toggle the show/hide
attribute of a corresponding div.

So I have this:

$(function(){
    $(this).find('a.reminder').click(function(){
        $(this).toggle();
        $(this).blur();
        return false;
    });//end click
});

However, in this function I'm toggling the title link itself, which is NOT
what I want.  I want to toggle the corresponding div.  so, the titles look
like this in html:

<a href="#" class="reminder" id="areminder">Create Reminder</a>

I would like to use the id ("areminder") in this case to now toggle the div
"div_areminder".  How do I find the id of each of these a tags to apply
toggle like this:

    find id method
    $('#div_' + idofatag).toggle();

??

That's my question.  That you very much.  Have a nice day.


Reply via email to