I have a DOM element similar to Facebook's "View friends" popup. I have a table with a list of rows, on which I can add tags to those rows:
<tr id="124"></tr>
When the row is clicked there's a modal popup that is created and lets the user choose tags they want associated with that row, sort of like this:
<div class="popup">
<div class="popup-body-row" id="3434">Add tag 3434</div>
<div class="popup-body-row" id="2112">Add tag 2112</div>
//etc.
</div>
I have the following javascript:
$('.popup-body-row').live('click', function(event) {
var popupRowId = event.currentTarget.id
// post for sending this to the server omitted
});
That gets the popupRowId, but doesn't get the originating element to associate with the popupRowId. I could build the popup so that the tr id is associated with it:
<div class="popup" id="124">
// everything else is same as before
</div>
And then add this line to my javascript:
var trRowId = e.currentTarget.parentNode.id;
That works, but if I start adding elements to my popup div so that the parent node isn't the parent node any longer, it breaks and I'll have to rewrite it.
Any advice would be appreciated, but the way I'm doing it has a certain "code smell." Thanks!
Edit: Short version, I have a row element, each associated with a unique object. I put the object's id as the attribute. When I click that row element a (potentially) complex DOM element is created giving the user a choice of tags to associated with the row element. If I use "parentNode" to find which row was clicked it breaks if my designer comes by and adds elements to the popup. What's the best solution for this? Associating the tr row id with the class "popup" and then searching the entire DOM for the class when a tag is added? Or putting the tr id on all div elements in the popup so even if my designer adds a new parent, the id will propagate to it?