jQuery Hide part of a string based on text -


if have html like:

<div class="text">good stuff hide me</div> <div class="text">great stuff hide me</div> <div class="text">best stuff hide me</div> 

and want hide "hide me" in every instance of div.text you're left with

good stuff
great stuff
best stuff

how jquery?

this $("div:contains('hide me')").hide(); hides entire string. how can isolate text want hide?

if want remove text, use:

$('div.text').text(function (i, t) {     return t.replace(' hide me', ''); }) 

jsfiddle example

to hide it, use:

$('div.text').html(function (i, t) {     return t.replace('hide me', '<span class="hidden">hide me</span>'); }) 

with css .hidden { display:none; }

jsfiddle example


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -