1
I’m trying to identify which email tr
that was clicked. My problem is that regardless of the tr
that I click, always returns me the same value.
Note: I would like to know the value of the cell, not the whole line.
$("#modelTable > tbody").delegate('tr', 'click', function () {
console.log(document.getElementsByTagName('tr')[1].textContent);
});
#modelTable{
border-collapse: collapse;
width: calc(100% - 5px);
}
#modelTable td, #modelTable th{
border: solid 1px lightgray;
}
#modelTable th{
font-weight: bold;
text-align:center;
}
#modelTable td{
cursor: pointer;
}
#modelTable tr:nth-child(even){
background-color: #f2f2f2;
}
#modelTable tr:hover{
background-color: #ddd;
}
#modelTable th{
padding-top:5px;
padding-bottom:5px;
text-align: left;
background-color: #4682B4;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="modelTable">
<thead>
<tr>
<th><spam class="lang" key="">Id User</spam></th>
<th><spam class="lang" key="">UserEmail</spam></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
How can I solve this problem ?
We answered together hehe only that yours was better than mine, because I used the each without need ;) . Just alert him to exchange the delegate for on.
– LeAndrade
@hugocsl Thanks for the reply. really worked, however I would like to pick up only the email, and not whole line. I’m not able to abstract the 'td' tag from this'.
– Levi
@Leandrade thanks for the remark! I left the mention in the edition ;)
– hugocsl
@Levi is now clear what he needs, because in your question you don’t say anything about just taking the email... in fact it’s almost another question what you’re talking about now. Because in the question you speak of TR not of content of just a TD etc...
– hugocsl
@hugocsl Pardon for not having made me understand. I will edit the question.
– Levi
@Levi updated the script, now just takes the text from the last td
– hugocsl
@hugocsl Thank you, I marked your reply because I found your resolution better.
– Levi
Opa :D, @Sam’s explanations are very pertinent, but it was worth the strength if it makes it easier for you that’s what matters. Vlw
– hugocsl