Reputation: 1
I have a jquery function that suppose to delete last dynamic created div it delete first time but when I try to delete again it's giving me
Microsoft JScript runtime error: 'null' is null or not an object
<script type="text/javascript">
jQuery("btnDeleteALineButton").click(function(e){
var lineCount = GetServiceLineCount();
if(lineCount > 0 ){
$('ctrlServiceLine'+lineCount).remove();
lineCount = lineCount -1;
}
//e.preventDefault()
});
</script>
When I put alert I see that firt time give lineCount correct but never do -1
can some one please help me
Upvotes: 0
Views: 49
Reputation: 329
Try to put var lineCount = GetServiceLineCount(); into jquery initialization so that lineCount becomes global variable
Upvotes: 0
Reputation: 8527
Your button selector is incorrect. If you are targeting id, change ("btnDeleteALineButton") to ("#btnDeleteALineButton"). For class use (".btnDeleteALineButton")
The same applies for the second selector.
Upvotes: 1
Reputation: 3581
Linecount is just a local variable inside the function. GetServiceLineCount() is always returning the same number.
Upvotes: 0