Reputation: 3827
I have onclick event. And I want to put double quote inside it. for example:
<a
onclick="document.getElementById('my_div').innerHTML='<a href="omer.php">link_2</a>'">
link
</a>
How can I do it? I want to put the html code inside the event without outside javascript function.
Upvotes: 0
Views: 1440
Reputation: 74036
You could circumvent the problem altogether, if you separate presentation from logic:
<a id="myLink">link</a>
<script>
document.getElementById( 'myLink' ).addEventListener( 'click', function(){
document.getElementById('my_div').innerHTML='<a href="omer.php">link_2</a>';
});
</script>
EDIT
As noted in the comments: addEventListener()
would have to be adjusted for older IE versions before IE9 to attachEvent()
. The principle, however, stays the same.
Upvotes: 1
Reputation: 193261
Like this:
<a onclick="document.getElementById('my_div').innerHTML='<a href=\'omer.php\'>link_2</a>'">link</a>
so you escape href=\'omer.php\'
.
Upvotes: 0