javascript - jQuery remove duplicate row(s) on output loop -


im looking jquery script run when results output on screen.

while running output loop, need jquery @ rows see if row similar id exists, if does, need remove current row output has duplicate id.

i constructing tr "id" passing in unique value db call , appeding "row_". in end make id "row_6373" (6373 being unique value).

<table> [while loop]             // jquery script right here...      <tr id="row_6373"><td></td></tr>     <tr id="row_988732"><td></td></tr>     <tr id="row_6435"><td></td></tr>     <tr id="row_6373"><td></td></tr> row output [/while loop] </table> 

as loop running need jquery check see if row id "row_6373" exists, if need remove last instance of row_6373. happen several time in output loop. "row_6373" come check thousand times.

right doing this: running @ beginning of loop see if row id exists, removing though.

<script> $(function(){     if($("#action_row_" + {{ action.product.id }}).length){         $("#action_row_" + {{ action.product.id }}).remove();     } }) </script> 

thanks help!

you testing see if length not undefined. , removing elements match selector. want this:

$(function(){     if($("#action_row_" + {{ action.product.id }}).length > 1){         $("#action_row_" + {{ action.product.id }}).last().remove();     } }) 

edit: should using classes instead of id's if you're having duplicates: #action_row_ should .action_row_


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -