Search code examples
javascriptc#jqueryhtmlstringbuilder

Javascript Error: 'missing ) after argument list


I have the following StringBuilder and inside of it I want to append my html, I have the following code but I am getting this error: Javascript Error: 'missing ) after argument list

Although in stackoverflow there are dozens of question with this same title, I checked all of them and could not solve my error.

StringBuilder emplDiv = new StringBuilder();
emplDiv.Append("$('.ulEmployeeSearch').append('<div class='col-lg-3 col-md-4 col-sm-6 col-xs-12'><p>test<p></div>')");

Please help me.


Solution

  • The problem is because in the JS string you're creating is this:

    $('.ulEmployeeSearch').append('<div class='col-lg-3 col-md-4 col-sm-6 col-xs-12'><p>test<p></div>')
    

    You can now see from the syntax highlighting that the quotes you're using to delimit the string are the same as those wrapping the attribute values - hence the error. You need to escape the inner quotes:

    emplDiv.Append("$('.ulEmployeeSearch').append('<div class=\"col-lg-3 col-md-4 col-sm-6 col-xs-12\"><p>test<p></div>')");