How make this jquery function reusable?
- by Pandiya Chendur
Comsider this jquery function,
function showresults(jsonobj)
{
$.each(jsonobj, function(i, employee) {
divs += '<div class="resultsdiv"><br /><span style="display: inline-block;width:150px;" class="resultName">' + employee.Emp_Name + '</span><span class="resultfields" style="padding-left:100px;">Category :</span> <span class="resultfieldvalues">' + employee.Desig_Name + '</span><br /><br /><span id="SalaryBasis" class="resultfields">Salary Basis :</span> <span class="resultfieldvalues">' + employee.SalaryBasis + '</span><span class="resultfields" style="padding-left:25px;">Salary :</span> <span class="resultfieldvalues">' + employee.FixedSalary + '</span><span style="font-size:110%;font-weight:bolder;padding-left:25px;">Address :</span> <span class="resultfieldvalues">' + employee.Address + '</span></div>';
});
}
Here i am iterating my json data and drawing div elements.... As you see these div elements are hardcoded how to pass these html div elements dynamically by a variable...
var divs=<div></div>
function showresults(jsonobj,divs)
{
$.each(jsonobj, function(i, employee) {
divs += divs
Is this correct way of doing but there will be an error employee object wont be there know when my divs variable declared outside the function... Any suggestion...