0

This changes

  1. "https://www.youtube.com/channel/blah" to
  2. "https://www.youtube.com/channel/blah/videos"
$(".yt-user-name.spf-link").attr("href", function(i, href) {  
    return href + '/videos';
});

I was wondering how I can change "https://www.youtube ..." to "https://www.m.youtube ..."

Possible solutions(?):

  1. How to replace element's attr href with each ? // strip url
  2. https://stackoverflow.com/a/179717/2038928
Community
  • 1
  • 1
computerguy
  • 177
  • 9

2 Answers2

3

you can use .replace to replace the part of string:

$(".yt-user-name.spf-link").attr("href", function(i, href) {
  return href.replace("www.you","www.m.you") 
});
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0

$(document).ready(function(){
    $('a').each(function(){
        this.href = this.href.replace('https://www.youtube.com', 'https://www.m.youtube.com');
    });
});
computerguy
  • 177
  • 9