javascript - jQuery attr() doesn't support property or method 'replace' -


i have following script works fine in chrome/firefox not in ie.

object doesn't support property or method 'replace'

i need replace part of url , open link in new tab. running behind secure site , external links gets server name in front of that, need replace 'http:'

$('a[href*="youtube.com"]').attr("href", $('a[href*="youtube.com"]').replace ("https://serverdomain.com/", "http:")) 

on ie above script throwing error.

firstly, attempting use replace on jquery object, hence you're getting replace undefined error. secondly, attr() can take function can use return replaced value more simply. try this:

$('a[href*="youtube.com"]').attr("href", function(i, value) {     return value.replace("https://serverdomain.com/", "http:"); }); 

i imagine need change http: http:// make sure urls remain valid.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -