vovina
vovina

Reputation: 373

Remove texts inside a span containing other tags

I have this span need to get rid og texts in side:

<span class="filter_column filter_date_range">From <input type="text" class="date_range_filter form-control" id="applicationList_range_from_6" rel="6" value="from"></input> to <input type="text" class="date_range_filter form-control" id="applicationList_range_to_6" rel="6" value="to"></input></span>

How can I remove text "from" and "to"?

Thanks

Upvotes: 2

Views: 102

Answers (1)

Ja͢ck
Ja͢ck

Reputation: 173542

You can filter the text nodes out and then remove them:

$('.filter_date_range').contents().filter(function() {
    return this.nodeType === 3; // filter text nodes
}).remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="filter_column filter_date_range">From <input type="text" class="date_range_filter form-control" id="applicationList_range_from_6" rel="6" value="from"></input> to <input type="text" class="date_range_filter form-control" id="applicationList_range_to_6" rel="6" value="to"></input></span>

The advantage of this approach is that any event handlers that were attached to the other elements aren't affected.

Upvotes: 4

Related Questions