I need to replace every instance of a an img tag that starts with http://player.vimeo.com with another url.
For example, you might find this in the code of the page:
<img src="http://player.vimeo.com/video/4887233">
I’m trying to make a jQuery script that will find every img src that begins with http://player.vimeo.com and replace the src with another string (it will be the same string for every vimeo link, essentially one variable).
How do I find the vimeo links and make sure the entire link is replaced no matter the length (some links will be longer than others but will always start with the same string)?
Select all the
imgwith an attribute starts with selector:The above will replace
player.vimeo.comin thesrcwithnew.url.com. If you need to set anothersrcaltogether, just dothis.src = 'new url';.It’s worth noting that when you want to change native attributes such as
src,eachwill perform much better compared toattr, as can be seen in this jsPerf.Check out demo on jsFiddle.