Reputation: 1715
I would like to add a custom id tag e.g. id = keys[key][each]
as part of the html that's being appended to the new_resumes
class e.g. I would like
<div class = "filtered_results" id = keys[key][each] ...
instead with the code below - when I use the attr
or prop
tag it adds an id to the new resumes class. I appreciate my code is not the 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>");
for (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]);
Upvotes: 1
Views: 83
Reputation: 6265
If I understand your question, you want to add the ID to the filtered_results
div you are creating?
You should just concatenate it like 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 this part: id='" +keys[key][each][0] +"'
Right now, you are calling .prop
on the current element which is still the .new_resumes
element.
Upvotes: 2