0

I would like to add a rel to all links that contain a youtube link. This is what I am working with - but it's not working. Any ideas?

$('a[href:contains("youtube.com")]').attr('rel', 'prettyPhoto');

I found a couple of other questions but not exactly like my request. This was the closest Select <a> which href ends with some string and posted my question there - but not sure if anyone would see it as it gets posted as an 'answer' not a question.

Community
  • 1
  • 1
  • 1
    You should not post your question in answer section, please delete your question in that page. – Ram Jan 22 '13 at 03:26

1 Answers1

3

:contains selects all elements that contain the specified text, you should use Attribute Contains selector instead.

$('a[href*="youtube.com"]').attr('rel', 'prettyPhoto');
Ram
  • 143,282
  • 16
  • 168
  • 197
  • Perfect. This worked like a charm. So in this case since I was using a href (an attribute) I needed to use the 'attribute contains'. But if I was not using an attribute I could have used the :contains? just making sure for future purposes like p:contains just as an example. – ckinteractivedesign Jan 22 '13 at 03:34
  • @ckinteractivedesign Yes, you can code `$('p:contains(something)')`. – Ram Jan 22 '13 at 03:42
  • great! thank you for your help. P.S. deletedmy question in the 'answers' on the other page. – ckinteractivedesign Jan 22 '13 at 03:48