Question

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!

Was it helpful?

Solution

$('div').click(function() {
    $(this).attr('id');
});

OTHER TIPS

Try this:

$('div[id]').click(function(){
  alert(this.id);
  return false;
});

This adds an event listener to all divs that have an id.
The return false; part stops propagation. Thus if you have nested divs that have id's only the bottom(inner) one will show the alert, and then stops the event bubbling.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top