user455318 user455318 - 1 year ago 138
jQuery Question

Remove text after element

I am trying to remove the text after the icon.

<i class="flagstrap-icon flagstrap-as" style="margin-right: 10px;">x</i>France


The problem is that next() will not work without an element.



Any idea to remove the text after the icon?

Answer Source

jQuery can't really target nodes that aren't elements, but plain JS can



Note that this uses the native remove(), which is not supported in older browsers, if you have to support those, you'd do

var node = $('.flagstrap-icon').get(0).nextSibling;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download