1
Simple question, but I can’t find a way to do it. I need to replace a value within one of the "cells" of each row in this table. Follows the code (extensive but simple):
<div class="col s12">
<div class="analists">
<div class="analists-header">
<div class="line">
<div class="col s3">
Login
</div>
<div class="col s5">
Nome
</div>
<div class="col s2">
Chat em Andamento
</div>
<div class="col s2">
Max Chats
</div>
</div>
</div>
<div class="analists-content">
<div id="listAgent">
<div class="line">
<div class="col s3">
601305
</div>
<div class="col s5">
601305
</div>
<div class="col s2">
4
</div>
<div class="col s2">
4
</div>
</div>
</div>
<div id="listAgent">
<div class="line">
<div class="col s3">
601150
</div>
<div class="col s5">
601150
</div>
<div class="col s2">
2
</div>
<div class="col s2">
4
</div>
</div>
</div>
<div id="listAgent">
<div class="line">
<div class="col s3">
601160
</div>
<div class="col s5">
601160
</div>
<div class="col s2">
1
</div>
<div class="col s2">
4
</div>
</div>
</div>
<div id="listAgent">
<div class="line">
<div class="col s3">
601560
</div>
<div class="col s5">
601560
</div>
<div class="col s2">
2
</div>
<div class="col s2">
4
</div>
</div>
</div>
<div id="listAgent">
<div class="line">
<div class="col s3">
601226
</div>
<div class="col s5">
601226
</div>
<div class="col s2">
3
</div>
<div class="col s2">
4
</div>
</div>
</div>
<div id="listAgent">
<div class="line">
<div class="col s3">
601457
</div>
<div class="col s5">
601457
</div>
<div class="col s2">
3
</div>
<div class="col s2">
4
</div>
</div>
</div>
</div>
</div>
</div>
Well. I tried for a long time, and the closest I could get was this:
$('.s3').text($('.s3').text().includes('601305') ? 'teste' : '');
to see if I could replace the value of 601305 in the table in the first column with the word 'test', but in doing so I end up replacing it in the whole column, all cells are equal. I need to put a different word for each code in each cell, so I need to refer only to that cell in the table, not the whole column. The problem is that the class of all rows/columns is the same, I cannot refer to one alone.
How should I proceed?
Just one observation, ids should be unique in HTML documents.
– LeAndrade
I agree, however, I didn’t make the site, I’m just developing a script to be added to it, I can’t change the rest.
– Máttheus Spoo
Following the observation that was said, the ensure that the
id
is unique is more important than it seems as it will ensure that your page is correct, and repeated ids can cause various parts of your site may not work properly, since<input>
,<radio>
, css, javascript, etc. So I strongly advise you to change the ids and respectively adjust the rest of the page to work with the new ids/classes. Enjoy and see how the documentation indicates that the id attribute must be unique on a page.– Isac
Isac, I don’t have access/power to change the html of the page. It was made by a company outsourced to my company, and I was asked to do only the script for internal use. I understand the importance of id being unique to each object, and it was exactly because it was not unique that I had this problem, but I have no way to change it on the page unfortunately.
– Máttheus Spoo
Well, if you can’t move, there’s nothing you can do about it. But as an aside I think it sucks that a third-party company gives you a site with pages that has repeated id’s, but turns out to be the professionalism we see around (just a vent :D)!
– Isac