JQuery Append if condition for select box
<p><strong>Could someone please help on how to add if condition to the below snippet?</strong></p>

<p>Snippet:</p>

<pre><code>function editStudesnt(data) {
$('#studentInfo').empty();
$('#studentInfo').append("&lt;div id=\"Search\" class=\"results\"&gt;"+
"&lt;span id=\"lb\"&gt;Student Name:"+data.stuName+"&lt;/span&gt;&lt;/div&gt;"+
"&lt;label&gt;Student Id: &lt;/label&gt;"+
"&lt;span id=\"SID\"&gt;"+data.stuId +"&lt;/span&gt;&lt;br /&gt;");
 }
</code></pre>

<p><strong>How do I add an if condition to the above snippet in the case where I need a condition as</strong></p>

<p>For example,</p>

<pre><code>if(data.courseId==1){
&lt;label&gt;Student Course: &lt;/label&gt; &lt;select id=\"courseId\"&gt;&lt;option value="" selected="selected"&gt;Mechanical&lt;/option&gt;&lt;option value=\"1\" selected="\selected\"&gt;Mechanical&lt;/option&gt;&lt;option value=\"2\"&gt;Computer Science&lt;/option&gt;&lt;option value=\"2\"&gt;Electronics&lt;/option&gt;&lt;/select&gt;"
}
if(data.courseId==2){
&lt;label&gt;Student Course: &lt;/label&gt; &lt;select id=\"courseId\"&gt;&lt;option value="" selected="selected"&gt;Mechanical&lt;/option&gt;&lt;option value=\"1\" &gt;Mechanical&lt;/option&gt;&lt;option value=\"2\" selected="\selected\"&gt;Computer Science&lt;/option&gt;&lt;option value=\"2\"&gt;Electronics&lt;/option&gt;&lt;/select&gt;"
}
</code></pre>

<p>The above code is working fine. But the problem is when I have more courses, the same codes repeats in every conditions. So can anyone please provide me a solution where I can write the if condition inside the option say, MechanicalComputer Science.</p>
