1

I have here an embed code from youtube and Im using a plugin to show that video

<object width="350" height="200">
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie" value="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" />
<param name="wmode" value="transparent">
<embed src="http://www.youtube.com/v/KVu3gS7iJu4&autoplay=0&loop=0&rel=0" type="application/x-shockwave-flash" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" width="350" height="200">
</embed>
</object>

My problem is I cannot edit those codes, I need to change the "&" sign to "&amp;" for w3c validation, is this possible using jquery

here is My sample fiddle which is not working and dont know how http://jsfiddle.net/kfX9M/

2
  • 1
    You don't need to, don't worry about it... Commented Dec 14, 2012 at 5:48
  • its important to me also to know how to do it. :-) Commented Dec 14, 2012 at 5:51

2 Answers 2

2

Changing it with jQuery won't make your HTML valid. You could change it server-side with some PHP:

$dom = new DOMDocument();
$dom->loadHTML($your_embed_code_here);
$xpath = new DOMXPath($dom);
$items = $xpath->query("//*[contains(@href,'&')]");
$l = $item->length;
for($i=0; $i<$l; $i++) {
  $items->item($i)->setAttribute("href",str_replace("&","&amp;",$items->item($i)->getAttribute("href")));
}
$out = $dom->saveHTML();

But, as mentioned by elclanrs, it really makes no difference.

Sign up to request clarification or add additional context in comments.

Comments

0

Hi dude i did with jQuery and Regular Expressions.,

<script type="text/javascript">
$(document).ready( function() {

var re=/&/g;

var value=$("param[name='movie']").val();

var modified_value=value.replace(re,'&amp;');

$("param[name='movie']").val(modified_value);

var src = $("embed").attr('src');

var src_modified_value=src.replace(re,'&amp;');

$("embed").attr('src',src_modified_value);

});
</script>

i think this may help you to resolve your problem.

To see it in action : http://jsfiddle.net/john_rock/7H2Hk/

2 Comments

I viewed the source code and i see this &amp;amp; instead of only &amp; :-)
Not possible to get '&amp;amp;' twice., and also regular expression 'var re=/&/g;' working to me in local and jsfiddle how could you say it's not working ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.