Possible Duplicate:
Create a link with javascript within it
I am trying to put a function into HTML tag which I am generating by javascript.
What I've got:
<script type="text/javascript">
var html = '';
html += '<div><a href="#" onclick="showBlock("#idTextBlocks");">Show Text Blocks</a></div>';
</script>
The showBlock("#idTextBlocks");
is the JQuery function which takes the ID of the component which needs to be show once the link is clicked.
function showBlock(id) {
$(id).show('slow');
}
The problem is that it is not working. It gets generated into:
<a #idtextblocks");"="" onclick="showBlock(" href="#">Show Text Blocks</a>
I've tried to change the quotes into '
singe: onclick="showBlock('#idTextBlocks');
but this just breaks all my javascript.
So the question is how to correctly pass a function into HTML <a>
tag's onclick
attribute if the tag itself is generated with javascript?