jquery - javascript element ":last" confusion -
i have question interaction of javascript code html code.
in part of lecture i'm working on, i'm put in work info .js file using for-loop, interacts other .js
, .html
file output job/role onto index.html , did so:
for (var = 0; < work.length; i++) { var role = htmlworktitle.replace("%data%",work[i].role); var employer = htmlworkemployer.replace("%data%",work[i].name); var description = htmlworkdescription.replace("%data%",work[i].description); var employerinfo = employer + role; $("#workexperience").append(htmlworkstart); $(".work-entry:last").append(employerinfo); }
the code works fine, i'm trying understand why need ":last" in ".work-entry:last". other file, helper.js has 1 element entry "work-entry" begin with, shown below:
var htmlworkstart = '<div class="work-entry"></div>'; var htmlworkemployer = '<a href="#">%data%'; var htmlworktitle = ' - %data%</a>';
so tried taking out ":last" , result started making random repetitions "employerinfo" output.
:last
jquery specific meta-selector. please see example in documentation clarification. select last element in current selection. since work-entry
css-class hints, there might multiple dom elements assigned class. code seems want append employerinfo
last work-entry
on page. suppose code executed, after new employer added dom. if wouldn't have :last
append current employerinfo
existing employers aswell instead of newly appended one.
Comments
Post a Comment