badwolfff
asked on
How do I remove a certain text element from a div using jQuery if it is only appears a certain number of times?
I have a dynamically generated div that looks like (two random examaples shown below):
or
What I need to do is check if the string | appears more than once or not. If it appears ONLY ONCE, then I need to remove it, otherwise it can stay as it is. I need to remove just that string leaving the rest of the DIV as it is.
I've been trying to detect this using: $('#association_content'). text().ind exOf('&nbs p; |& nbsp;  ;')
but I keep getting -1 in the console.log
thanks in advance
<div class="col-lg-6 col-sm-6 col-xs-12" id="association_content">
<img src="http://www.missionfamily.org/image/cache/catalog/marchio_fas-270x269.jpg">
<!--<img src="image/cart-ban.png"/>-->
<h1>FAS - Fondo Ambiente Sammarinese</h1>
<br>
| <strong><i class="fa fa-envelope-o"></i></strong> <a href="mailto:info@fondoambiente.sm?Subject=Messaggio%20da%20Mission%20Family:%20">info@fondoambiente.sm</a>
</div>
or
<div class="col-lg-6 col-sm-6 col-xs-12" id="association_content">
<img src="http://www.missionfamily.org/image/cache/catalog/MarchioPolisportivaStella-270x269.gif">
<!--<img src="image/cart-ban.png"/>-->
<h1>Polisportiva Stella S.G.</h1>
Via Abruzzo, 36 47923 Rimini RN<br>
<strong><i class="fa fa-phone"></i></strong> 0541781283 | <i class="fa fa-mobile"></i> 0541781283
| <strong><i class="fa fa-envelope-o"></i></strong> <a href="mailto:segreteria@polstella.com?Subject=Messaggio%20da%20Mission%20Family:%20">segreteria@polstella.com</a>
</div>
What I need to do is check if the string | appears more than once or not. If it appears ONLY ONCE, then I need to remove it, otherwise it can stay as it is. I need to remove just that string leaving the rest of the DIV as it is.
I've been trying to detect this using: $('#association_content').
but I keep getting -1 in the console.log
thanks in advance
Instead of .text() use .html()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.