Shelef
Shelef

Reputation: 3827

How to put double quote inside double quote

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

Answers (2)

Sirko
Sirko

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

dfsq
dfsq

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\'.

http://jsfiddle.net/8T2wB/

Upvotes: 0

Related Questions