I am using jQuery to get the text value of multiple td
elements in a row:
var getText = $(this).closest("tr").text();
The value of getText
ends up being one long concatenated string of the text of each element with no breaks. Is it possible to add a delimiter for each new td
element that it gets the text value from?
I'd first suggest retrieving an Array of the cells' text, rather than a single String:
var cellTexts = $(this).closest("tr").find('td').map(function(){
return $(this).text();
}).get();
If you wish to have a single string, with a custom delimiter, you can then call Array.prototype.join()
, and specify the delimiter you wish to use, for example a comma:
var cellTexts = $(this).closest("tr").find('td').map(function(){
return $(this).text();
}).get(),
allText = cellTexts.join(',');
References:
Array.prototype.join()
.closest()
.find()
.get()
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With