Click here to Skip to main content
15,846,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This only works if row is 0. Why?

$('#Item').eq(row).trigger('change');


I'm trying to fire a trigger on the second cell in any row of a table who's Id is #Item.

What I have tried:

All kinds of versions of lame jquery attempts after googling all night.
Either what I try will only operate on table row 0 or not at all on any row.
Posted
Updated 19-Mar-21 12:45pm

IDs in an HTML document must be unique. Only one element in the document can have the ID Item, so $('#Item') (or document.querySelectorAll('#Item')) will only ever return a single element.

Based on your description, your table's ID is Item. If you call $('#Item').eq(1) you are asking for the second element in the document with the ID Item, which obviously can't exist.

I suspect you want something like:
JavaScript
$('#Item').find('tr').eq(row).trigger('change');
or
JavaScript
$('#Item tr').eq(row).trigger('change');

NB: If you have nested tables, this will not work properly; the rows of the nested tables will also be matched by the tr selector.

Assuming you've structured your table properly, you'll need:
JavaScript
$('#Item > tbody > tr').eq(row);
 
Share this answer
 
Thank you.

I will give that a go.
 
Share this answer
 
Comments
Patrice T 19-Mar-21 17:54pm    
Use 'have a Question or Comment?' button to communicate with author of Solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900