Thursday, 15 January 2015

javascript - Cannot add Id tag using JQuery -



javascript - Cannot add Id tag using JQuery -

i add together custom id tag e.g. id = keys[key][each]as part of html that's beingness appended new_resumes class e.g.

<div class = "filtered_results" id = keys[key][each] ...

instead code below - when utilize attr or prop tag adds id new resumes class. appreciate code not greatest.

for (var key in keys) { $(".new_resumes").append("<div class='filtered_results' style='color:white; background-color:red; text-align:center; height:20px; line-height: 20px'>" + key + "</div>"); (var each in keys[key]) { $(".new_resumes").append("<div class='filtered_results' style ='height:60px; text-align:center; height:60px; line-height: 60px;'>" + keys[key][each][0] + "</div>").prop('id',keys[key][each][0]);

if understand question, want add together id filtered_results div creating?

you should concatenate so:

$(".new_resumes").append("<div class='filtered_results' id='" +keys[key][each][0] +"' style ='height:60px; text-align:center; height:60px; line-height: 60px;'>" + keys[key][each][0] + "</div>")

take note of part: id='" +keys[key][each][0] +"'

right now, calling .prop on current element still .new_resumes element.

javascript jquery html

No comments:

Post a Comment