I have this short single line of code for assigning a variable.
var ulbl = $(e.target).is('.user-label') ? $(e.target)[0] : null;
Since I'm neurotic, the fact that I have to reference the first index of the jQ object bothers me. I know I could use .first()
or do $(e.target + ':first')
but I'm not convinced those choices are the best either.
Just to establish a variable inside an $.on('click', 'tr')
everything runs as expected, I'm more interested if it can be refactored any further.
HTML
<tbody data-bind="foreach: items">
<tr data-bind="attr: {
'item-type': item_type,
'list-idx': id,
'section-id': sectionID,
'group-id': displayOrder,
},
css: {
'text-info': headerDepth() > 1,
'bg-info': headerDepth() > 1
}">
<!-- First Column -->
<td class="button-group-col" data-bind="visible: headerDepth() > 1 ? buttonGroup() ? true : false : true">
</td>
<!-- Second Column -->
<td style="width: 80%;" data-bind="visible: headerDepth() > 1 ? true : false,
attr: {
colspan: headerDepth() > 1 ? buttonGroup() ? 2 : 3 : 1
}">
</td>
<!-- Third Column -->
<td class="time-stamp-col" data-bind="visible: headerDepth() > 1 ? false : true">
<div data-bind="foreach: fill_data">
<span class="label label-success user-label" data-bind="text: userID, attr: {
title: f_time,
'user-id': userID
}">
LABEL
</span>
</div>
</td>
</tr>
</tbody>
$(e.target)[0]
is the same as juste.target
. \$\endgroup\$