i am trying to learn and understand objects in javascript and has come up with the following script:
jQuery(document).ready(function(){
var test = new Project('Anton');
$('#btn_add_project').click(function(){
test.addElement();
});
});
function Project(name)
{
this.panel = $('#worksheet_panel');
this.name = name;
function changeName(name)
{
this.name = name;
}
function addElement()
{
this.element =
'<div id="1" class="col-md-3 table-bordered worksheet_overall_box" draggable="true" ondragstart="drag(event)">'+
'<div class="table-bordered title_box">'+
'<h4 class="title text-center worksheet_title">Dansk handicap</h4>'+
'</div>'+
'<div class="worksheet_box">'+
' <div class="list-group ">'+
' <a href="#" class="list-group-item">'+
' <h5 class="list-group-item-heading">Marc</h5>'+
' <p class="list-group-item-text">...</p>'+
' </a>'+
' </div>'+
' <div class="list-group ">'+
' <a href="#" class="list-group-item">'+
' <h5 class="list-group-item-heading">'+name+'</h5>'+
' <p class="list-group-item-text">...</p>'+
' </a>'+
' </div>'+
' <div class="list-group">'+
' <button class="btn-block btn-primary btn">Add</button>'+
' </div>'+
'</div>'+
'</div>';
this.panel.appendChild(this.element);
}
}
however when i run the click function i get the following error:
TypeError: test.addElement is not a function
test.addElement();
can anyone tell me what i am doing wrong?