mmcsacc mmcsacc - 1 year ago 46
HTML Question

How do I return the value of the class <div> without returning the value of the <span>

How do I return the value of "Jhon Doe" without the "x"

<div class="chip"><span class="closebtn" onclick="this.parentElement.remove()">&times;</span>John Doe</div>
var array = $( ".chip" )
.map(function() {
return this.textContent; //changeing only this line

Answer Source

You can do it like that:

// Take the whole inner HTML, split it at the span closing tag,
// take the second element which is the desired text
var text= $( ".chip" ).html().split('</span>')[1];

If you need it for multiple elements, you can use the jQuery .each() function like this:

var array = [];

$( ".chip" ).each(function(){