Passing variables with Jquery
Hi everyone,
I am a newbie to the world of Jquery and I am trying to get my head around something that is probably very simple.
I have a list of links on my page.
-
<script language="javascript">
$(document).ready(
function()
{
// we'll put our code here
$('#wrapper').hide();
$('a#slick-toggle').click(function()
{
$('#wrapper').toggle('slow');
//
});
</script>
I am looking to toggle a div from a series of links in a page.
<a href="" id="link1">link 1</a>
<a href="" id="link2">Link 2</a>
<a href="" id="link3">Link 3</a>
<a href="" id="link4">Link 4</a>
I know if i was using good old JS i would use a onclick method and append a couple of variables within that and invoke a particular function.
so in a nutshell. The list of links could be generated dynamically and each invokes a function that is simillar yet different info is to be displayed. Rather then writing seperate functions to display each item, how would i encapsulate this into a single function but generate different
possibly something like
$('a#'+obj).click(function()
{
}
so how would i dynamically capture the id of the element that i have clicked ? and how would i then make it invoke a particular method?
any help greatly appreciated.