Reputation: 747
I have a delete image that that is triggered by a 'click' handler. I'm passing the element parameter into the function that triggered the event, which is the delete image.
Is there a way I can find the input where type="text"
for the table row that of the delete image that was clicked?
Here is the code I'm working with:
A4J.AJAX.AddListener({
onafterajax: function(req,evt,data) {
j$('[id$=deleteImage]').on('click', function(elem) {
console.log('the delete button was clicked');
console.log('************** before ' + localStorage.activeButtons);
var activeArray = localStorage.activeButtons.split(',');
var idx = activeArray.indexOf('account');
if (idx > -1) activeArray.splice(idx, 1);
localStorage.activeButtons = activeArray.join(',');
console.log('************** after ' + localStorage.activeButtons);
});
var lastRow = j$('table[id$=participantTable] tbody tr:last');
var active = localStorage.activeButtons.split(',');
var dataRows = j$('tr.dataRow');
dataRows.each(function(index, elem) {
updateImages(elem, active[index]);
});
}
});
I need to find the input[type="text"]
in the table row that the delete image was clicked and get the id of that input field and check if the id contains one of the following values: contact, user or account
. I need to pass the value contained in the input id into the indexOf() method.
Thanks for any help.
Upvotes: 2
Views: 9003
Reputation: 10562
Answer for the question:
$("#TblName tbody tr input[type=text]").each(function(){
console.log($(this).val());
});
$("#TblName tr input[type=text]").each(function(){
console.log($(this).val());
});
$(".TblClass tr .InputClass").each(function(){
console.log($(this).val());
});
Upvotes: 0
Reputation: 28837
Try this:
j$(this).closest('tr').find('input[type="text"]:visible');
inside the click handler
j$('[id$=deleteImage]').on('click', function(elem) {
jQuery .closest() - get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
Upvotes: 5