views:

48

answers:

1

I'm going to use the text from the jquery example, For example, consider the HTML:

<lots of divs to get to here>

<div id="#targetid_0">
  Click here
</div>
<div id="#targetid_1">
  Trigger the handler
</div>

I have a series of questions that are plaguing me...

Assuming that I click on 'Click Here' or 'Trigger the Handler':

  1. If I'm assigning a value via the attr(targetid_x,JSON.ID), how can I use alert to show me that value? It's driving me nuts!
  2. How do I find out the specific clicked #tag? (sort of related to question 1).

I'd like to see if this can be accomplished with Event Delegation or at least without classes.

Halp!

A: 
$('div').click(function() {
    $(this).attr('id');
});
Catfish
so, should alert($(this).attr('id')); put something up in an alert box? Because it doesn't.Here's my function:$('.section1').click(function(event){ var tmp =$(this).attr('id'); alert (tmp); });I even tried it as alert ($(this).attr('id')); <= empty alert box.
Kevin Flavin
I'm not a jquery expert, but i don't think you need the "event" in your function. Try taking that out. Also try putting something like "test" in the alert box just to make sure that works.
Catfish
Oh also when declaring variables i've had some trouble with this. Try doing var tmp = ($(this).attr('id'));
Catfish
re:event, good point, that was inadvertantly left in from one of my permutations and research. Thank you.lol, I'm getting results, but just as perplexing...declaring: var tmp = ($(this).attr('id'));........alert("[o]"+$(this)[0]); // gives [o][object HTMLDivElement].......alert("attr"+$(this).attr('id')); //yields attr and nothing else........alert("just tmp"+tmp); //yields just tmp and nothing else..........This seems so easy, yet it's been killing me for days. i'm using jquery 1.4.1, btw. but I jsut switched today, and there hasn't been any change in results. I'm defeated.
Kevin Flavin