-1

I'm trying to remove redundant dashed lines from a client's blog site because its erratic lengths are butting heads with the responsive design. Example: ---------------------------------

I created a jquery plug-in to remove individual lines from one post:

$('p:contains(——————————————————————————————-), 
p:contains(———————————————————————–),      
p:contains(————————————————————————————-), 
p:contains(———————————————————————————), 
p:contains(——————————————————————–), 
p:contains(————————————————————-), 
p:contains(————————————————————————————————), 
p:contains(—————————————————————————), 
p:contains(————————————————————), 
p:contains(———————————————————————————–), 
p:contains(——————————————————————————-)').each(function() {
$(this).remove();
});

But even this method is redundant lol. I tried rewriting like so using regex:

$('p:contains(----)').each(function(text) {
    var hyphen = text.replace(/\u00AD/g,'');
    return hyphen;
});

It didn't work and I've since been stuck on it for an hour. If anyone could give me a push in the right direction I would greatly appreciate it. Thanks!

matenji
  • 365
  • 3
  • 5
  • 12

1 Answers1

2

Giving the jQuery .text() method a function is the way to perform a direct replacement of an element's text. The function receives the old text as its second argument, and whatever it returns will be used as the replacement.

$("p:contains(---)").text(function(i, text) {
    return text.replace(/-{3,}/g, '');
});
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Great Barmar, that's exactly what I was looking for. :) Thank you thank you. So now my issue is that a PHP filter hook from the blog platform added the

    tags dynamically after page load, and my jquery code is wrapped in $(document).ready(); so it's not working. Do I need to wrap the code so that it executes after the

    tags? I tried $(window).bind("load", function()) { code here } but it's still not working. Is that the right format to use?

    – matenji Jun 29 '13 at 03:13
  • Yes, it sounds like it. See if the blog platform provides a hook that you can assign to for your code. – Barmar Jun 29 '13 at 03:14
  • I just put the code in the head and it worked fine, thanks Barmar. :) – matenji Jun 30 '13 at 20:21