jQuery Data Type How to - Escape quotes and double quotes automatically








Question

We would like to know how to escape quotes and double quotes automatically.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<style type='text/css'>
#p {<!--from   w  ww  .j a va  2s  .  c  o  m-->
  margin: 1em;
  padding: 1em;
  border: 3px solid red;
}
</style>
<script type='text/javascript'>
$(function(){
    $( '#pp' ).html( '<a href="#"><img src="http://www.java2s.com/style/download.png"></a>' );
});
</script>
</head>
<body>
  <div id="p">
    <div id="pp"></div>
  </div>
</body>
</html>

The code above is rendered as follows: