javascript - jQuery str.replace not working -
i need search string (video embed url) once page loads , replace &
&
. best guess code have tried seems have no effect:
(function ($, document, undefined) { $(document).ready(function(){ var str = $( "iframe" ).attr( "src" ); str = str.replace(/&/g,"&"); $( "iframe" ).attr( "src",str ); }); })(jquery, document);
there once iframe
on page , looks this:
<iframe src='http://player.vimeo.com/video/72874423?title=0&byline=0&portrait=0;api=1' width='615' height='355' style='width:615px;height:355px;'></iframe>
what doing wrong?
the problem once javascript manipulates dom, &
encoded html &
. actual javascript replace &
&
works fine.
see this fork of commenter's jsfiddle. when alert happens, string has &
, once it's written document, displays &
Comments
Post a Comment