javascript - Mapping between button and word for tooltip -


while selecting quantity during order placement have 2 buttons, - , +, decreases/increases quantity number (not beyond min , max amount).

after reaching min, - button grayed out. after reaching max, + button grayed out. tooltip appears says quantity cant less <min> or quantity cant more <max>.

if ($button.hasclass("minus") && $quantity <= $("#dropdown").data("min")) {   $button.addclass("grayout");   $("#tooltip").html("quantity can't less " + $("#centerbox").html()).show(); } else if ($button.hasclass("plus") && $quantity >= $("#dropdown").data("max")) {   $button.addclass("grayout");   $("#tooltip").html("quantity can't more " + $("#centerbox").html()).show(); } 

i have if else statement job. since contents of if else blocks same except "less" , "more". whats best way optimize code?

all elements created js:

var $centerbox = $("<div>",{id:"centerbox"}); var $negbutton = $("<input>",{type:"button","class":"custombutton minus",value:"-"}); var $posbutton = $("<input>",{type:"button","class":"custombutton plus",value:"+" }); 

these 3 elements siblings of conainer div. var $button = $(ev.target); created onclick event on button elements.

things have tried (but not yet satisfied):

  • have conditions clubbed "||" , within block, check class again , modify text accordingly.
  • have map outside of function maps button element word
  • modify tooltip text cant go beyoond range <min> , <max>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -