0

i've got this function and i need 'click' event to stop after input value reaches 0 and less

 function clickPlus(e) {
                  var parent = e.target.parentNode,
                      span = parent.querySelector('span'),
                      input = parent.getElementsByTagName('input')[0],
                      inner = span.dataset.one,
                      price = inner * (++parent.querySelector('input').value);          
                      span.innerHTML = price; // price takes an input value
                      if (price > 10){
                         return false; // error here 
                      }         
                      countPrice();                  
                }
            for(i=0; i<pluses.length; i++) eventsObj.addEvent(pluses[i],'click', clickPlus);
ddeadlink
  • 217
  • 1
  • 13

2 Answers2

-1

The 'countPrice' function fires regardless of the if statement.

Try the other way round with your if statement or add an else...

if(price>0)
{
    countPrice();
}
Cnalla
  • 1
  • 1
-1

Just unbind the click event from pluses[i]

You can unbind by calling the jquery unbind / off method.

$(pluses[i]).off('click');

value of pluses[i] is not given , so I am going to call the value as pluses[i] itself.

For more info - SO

jquery off method

Community
  • 1
  • 1
Jitin Kodian
  • 371
  • 3
  • 13