i have a selection of (2) elements, selected by this:
$(this).parents("tr:first").children("td").children("span");
when i do this:
$(this).parents("tr:first").children("td").children("span").text();
the texts in the spans (say a and b) are concatenated together (to ab), and thats almost what i want
But now i want to concatenate them by inserting a hyphen (-) in between (to a - b) I've tried this, but that doesn't work:
$(this).parents("tr:first").children("td").children("span").join(" - ");
Use $.map:
$.map(
$(this).parents("tr:first").children("td").children("span"),
function(element) {
return $(element).text()
})
.join(" - ");
$(this)
.parents('tr:first')
.children('td')
.children('span')
.append('-') // append hyphen to each span
.text();
Perhaps something like this...
var m = [];
$(this).parents("tr:first").children("td").children("span").each(function(index, element) {m.push(element.text());});
return m.join(" - ");
you could try this may feel a little heavy just not as complex.
$(this).parents("tr:first td span:eq(0)").text() + " - " + $(this).parents("tr:first td span:eq(1)").text()
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