I want to manipulate the attributes of an object when it is created dynamically.
In the code given below, I would like to increase the like attribute by calling the corresponding functions of the object. However the elements are created dynamically and passing a this in the onclick function will only refer to the anchor tag.
The idea is similar to this forum wherein each question has various ideas that can be approved or disapproved. How can I manipulate each object's attribute independently?
function idea(idea) {
this.ideatext = idea;
this.like = 0;
this.str = "\
<div class = 'entered'> \
<div class = 'text'> " + this.ideatext + "</div> \
<div class = 'anchors'> \
<a href = '' onclick = 'increase()'> Approve </a> \
<a href = '' onclick = 'decrease()'> Disapprove </a> \
</div> \
</div>";
this.increase = function() {
this.like++;
}
this.decrease = function() {
this.like--;
}
}
var ideaobj1 = new idea(someidea1);
var ideaobj2 = new idea(someidea2);