title: Passing a parameter to function with single quote
body: <p>How do I pass a parameter to a javascript function with <code>'</code> included</p>
  
  <pre><code>var name ="Lauren O'Donald";
  
  var htmlAnch='&lt;a onclick="javascript:selectEmployee(1100,"'+name+'");return false;" 
                   href="javascript:void(0);"&gt;O'Donald, Lauren&lt;/a&gt;';
  
   $(document).append($(htmlAnch));
  </code></pre>
  
  <p>The javascript function is not executing since the name <code>'Lauren O'Donald'</code> contains single quote.</p>
  
  <p>How can I add a parameter with <code>'</code> and prepare dynamic html to make it work?</p>
  
  <p>Here is the dynamic code to generate</p>
  
  <pre><code> var rows = new StringBuffer();
  
   $(data).each(function(index) {
        rows.append(String.format('&lt;tr&gt;&lt;td&gt;&lt;a href="No.aspx" 
                  onclick="javascript:selectEmployee({3},\"{1} {2}\");return 
                 false;"&gt;{0}&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;',
                  String.format("{0}, {1}", this.Surname, this.FirstName),
                  this.Surname,
                  this.FirstName,
                  this.Id
              ));
     });
  </code></pre>