javascript - Banners are disappearing from webpage. Any suggestions on how to fix this? -
i'm having issue labels @ top of page disappearing after click button. when click "show employees" button, "last name" "first name" , "region name" disappear.
here screenshots:
before clicking "show employees": https://imgur.com/a/zgu4j
after clicking "show employees": https://imgur.com/a/pqkoh
i have feeling issue displayemployees js function:
function displayemployees(data) { var table = ""; $.each(data.rows, function(index, row){ table += "<div class='row'>\n"; table += "<div class='col1'>" + row.emp_first + "</div>\n"; table += "<div class='col2'>" + row.emp_last + "</div>\n"; table += "<div class='col3'>" + row.region_name + "</div>\n"; table += "<button dbutton = " + row.employee_id + " class = 'deletebutton'> delete employee </button>"; table += "</div></br>"; }); $("#outputdiv").children("div:not(:first)").remove(); $("#outputdiv").html(table); $("#addemployeebutton").on('click', addemployee); $(".deletebutton").on('click', deleteemployee);
}
$("#outputdiv").children("div:not(:first)").remove(); $("#outputdiv").html(table); $("#addemployeebutton").on('click', addemployee); $(".deletebutton").on('click', deleteemployee);
}
here html:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>employee table</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h2 id="title">project 4 web app</h2> <div id="outputdiv" class="container"> <div class="row"> <div class="col1h">last name</div> <div class="col2h">first name</div> <div class="col3h">region name</div> </div> </div> <br> filter region  </br> <select> <option value="1">select</option> <option value="2">nw</option> <option value="3">sw</option> <option value="4">mn</option> <option value="5">ms</option> <option value="6">ne</option> <option value="7">se</option> </select> <div id="buttondiv"><br> <button id="showbutton">show employees</button> </div> <p> <h3>to add employee:</h3> <div class="divcol1">employee first name:</div><div class="divcol12"> <input type="text" id="emp_first"/></div><br> <div class="divcol1">employee last name:</div><div class="divcol12"><input type="text" id="emp_last"/></div><br> <br><div class="divcol1">region id:</div><div class="divcol12"><input type="text" id="region_id"/></div><br> <br><button id="addemployeebutton">add employee</button><br> <script src="jquery-3.1.1.min.js"></script> <script src="employee.js"></script> </body> </html>
any appreciated. thank in advance.
your selector isn't correct. instead of
$("#outputdiv").children("div:not(:first)").remove();
try
$("#outputdiv").children("> div:not(:first)").remove();
or shorter:
$("#outputdiv > div:not(:first)").remove();
explanation: selector finds column divs , not rows. take @ jquery documentation more info.
Comments
Post a Comment