JQuery selector: pass on id from array into function

Posted by user347256 on Stack Overflow See other posts from Stack Overflow or by user347256
Published on 2010-05-21T16:29:24Z Indexed on 2010/05/21 16:30 UTC
Read the original article Hit count: 155

Filed under:
|

I have a list of items

<div id="item1">somestuff</div>
<div id="item2">somestuff</div>
<div id="item3">somestuff</div>

When someone clicks on one of these, I need to take some actions based on the id (the number). Let's say hide it.

How can I make the function generic, and how can I pass the id into the function?

$(document).ready(function()
{
$("#item-howcanImakethisselectorgeneric?").click(function () { 
  $("#item-andhowcanIpasshteidintohere?").hide();
}
}

I'm a javascript/jquery newbie, any help (including rtfm) appreciated.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-selectors