Reputation: 1735
I have one line in php file like this:
<a class="hide-if-no-js" onclick="findPosts.open( '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='findPosts.open( '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?
Upvotes: 0
Views: 598
Reputation: 160943
$output .= "<a class=\"hide-if-no-js\" onclick=\"findPosts.open( 'media[]','$id' ); return false;\" href=\"#the-list\">$linktext</a>";
Your javascript string use single quote, so the html attribute should use double quote.
Upvotes: 2
Reputation: 9305
You can try:
$output .= '<a class="hide-if-no-js" onclick="findPosts.open( \'media[]\',\'' . $id . '\' ); return false;" href="#the-list">' . $linktext . '</a>';
OR
$output .= "<a class='hide-if-no-js' onclick='findPosts.open( \"media[]\", \"$id\" ); return false;' href='#the-list'>$linktext</a>";
Upvotes: 1