jquery is not refreshing the function
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开发者_Go百科 lineCount correct but never do -1
can some one please help me
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.
Linecount is just a local variable inside the function. GetServiceLineCount() is always returning the same number.
Try to put var lineCount = GetServiceLineCount(); into jquery initialization so that lineCount becomes global variable
精彩评论