How to write the javascript function as string in php?


I have one line in php file like this:

<a class="hide-if-no-js" onclick=" 'media[]','<?php echo $post->ID ?>' ); return false;" href="#the-list">Attach</a>

I need to write this line as a string in a php function, I tried this:

$output .="<a class='hide-if-no-js' onclick=' 'media[]','$id' ); return false;' href='#the-list'>'$linktext'</a>";

Seems the quote around 'media[]' is wrong and made the html of this line messed up. Could anybody help correct me?

$output .= "<a class=\"hide-if-no-js\" onclick=\" 'media[]','$id' ); return false;\" href=\"#the-list\">$linktext</a>";

Your javascript string use single quote, so the html attribute should use double quote.