When decreasing a counter, removing div

I have counter on a form that looks like: ![enter image description here][1] [1]: http://i.stack.imgur.com/Vl3XC.png When the user clicks the plus/minus icons, the counter increments and decrements correctly. What I am trying to do is add more form elements when the user clicks the plus sign, and then remove them if they select the minus sign. Here is my html:
Total attendees:
(include yourself in this count)
My jquery: $(document).ready(function() { $(function() { $("#inc").click(function() { var num = $(":text[name='qty']").val(function(i, v) { return Number(v) + 1; }).val(); $(this).addClass ('c' + num); var incrementVar = num; $('.additional').append("
Test
"); }); $("#dec").click(function() { $(":text[name='qty']").val(function(i, v) { if(Number(v) > 1){ return Number(v) - 1; } else{ return 1; } $("div").removeClass("a_" + Number(v) - 1); }); }); }); }); The code above is correctly appending the test divs, but will not remove. Any suggestions?
Your .removeClass call is unreachable, but that is not the only problem

以上就是When decreasing a counter, removing div的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏