howto catch jQuery for multiple links but not all

Posted by user247245 on Stack Overflow See other posts from Stack Overflow or by user247245
Published on 2011-01-02T14:42:12Z Indexed on 2011/01/02 14:53 UTC
Read the original article Hit count: 144

Filed under:

I'm trying to dig into jQuery but would like some feedback on how to do things the best way,

I have a list with items, which each contains a hidden div that should show upon click on it's parent,

list
  div:ed item1 with link
    hidden div
  div:ed item2 with link
    hidden div
  ..

My current solution is to trace the calling link by it's id and then reusing that ID for showing the correct hidden one:

$(document).ready(function() {
  //jQ should only trigger on links with id="cmLinkINT"
  $("a").click(function() {
    //see if it's a comment request.
    var s = $(this).attr("id");
    if (s.indexOf('cmLink') != -1) {
      //ok, it was a 'show'-link, get the id..
      var j = s.substring(6);
      //ok, now I have the id i want to show (detailsINT)
      return false;
    }    
  });
});

What's not clear to me is the best approach,

  • Should I use id for requesting a or trace the id of the parent div.

  • How to avoid that the code triggers on any link? Class?

Thankful for any feedback,

regards

//t

© Stack Overflow or respective owner

Related posts about jQuery