[jQuery] How to link myFunction(this) to a div
Hi
I'm new to jQuery and here's one thing that doesn't make sense. How
do I link an existing function with "this" as argument to a div?
The function to be called is really simple:
function test(e)
{
alert(e.id);
//Also tried e.getAttribute("id") or e.attr("id")
}
Here is what I tried so far inside the $(document).ready(function()
{}); part:
$("div.someClass").each(function(){
$(this).test();
});
$("div.someClass").each(function(){
$(this).test;
});
$("div.someClass").each(function(){
$(this).click(test);
});
$("div.someClass").each(function(){
$(this).click(test());
});
Alternatively, I tried:
function test(strId)
{
alert(strId);
}
$("div.someClass").each(function(){
var strId = $(this).attr("id");
$(this).test(strId);
});
$("div.someClass").each(function(){
var strId = $(this).attr("id");
$(this).click(test(strId));
});
Can someone point me in the right direction? Maybe it's just one of
the many different combo's I haven't tried, but I'm rather amazed that
something this basic is so difficult to get right (and find
documentation on).
Thanks!