0

I have this code on my site to find a specific hyperlinked text and hide, but this is removing the hyperlinks on all other texts, i do not want to do that,can someone tell me how do hide the specific text only without removing the hyper link on others?

this is my code

$('.myname').each(function() {
    var text = $(this).text();
    $(this).text(text.replace('rob-blank', '')); 

JSFIDDLE

thanks

user3735148
  • 11
  • 1
  • 4

2 Answers2

0

It sounds like you only want to grab a particular hyperlink. For this you will need a more particular selector; your selector will grab every tag with the class 'myname', which is likely too general for your purpose.

Try applying an id to the link you want to delete, and then use the id selector,

$('#<your id>').each(...);

instead.

The Velcromancer
  • 437
  • 3
  • 10
  • 2
    an .each() function on a group selected by id is kinda funny :) – Raffael Jun 25 '14 at 14:44
  • Yeah, but it attaches a scope to the element, which is kind of convenient in this case (in my opinion) – The Velcromancer Jun 25 '14 at 14:48
  • No it is not. Further more, if you have more than one element with this ID on the page, you'll have more other problems. If not, there is absolutely no reason to use ".each()" on an array that only have 1 element in it. None. – Ronen Cypis Jun 25 '14 at 14:58
0

Check the Fiddle Demo

Given this HTML

<a>Lorem</a><br />
<a>Ipsum</a><br />
<a>Dolor</a><br />
<a>Sit</a><br />
<a>Amet</a><br />

You could just do this:

$('a').each(function(){
    var current = $(this);
    if(current.text() == 'Dolor'){
        current.css('color', 'red'); // or anything else you want to do with this element...
    }
});
Ronen Cypis
  • 21,182
  • 1
  • 20
  • 25