- This topic is empty.
-
AuthorPosts
-
August 1, 2013 at 8:00 am #145363
hoeiesta
ParticipantHi,
I am trying to use the “Add (+/-) Button Number Incrementers” for a web page. The example has +/- both to the right but I’m trying to split them on each side of the number field.
Unfortunately it’s not working. Both buttons are being duplicated and one of them even adds/reduces by 2 instead of 1.
I have managed to hide the double รท but the double + is still visible.
Any help would be appreciated.
Link to pageThanks!
Here is the css:
.numbers-row {
overflow:hidden;
}
.buybutton {
margin: 5px 0 0 5px;
padding: 0;
text-indent: -9999px;
cursor: pointer;
width:20px;
height: 20px;
float: left;
position: relative;
text-align: center;
background: url(../images/icons/pluss-minus.png) no-repeat;
}
.inc {
left: -80px;
background-position: 0px -20px;
}
.dec {
left: -108px;
background-position: 0px 0px;
}and this is the jQuery:
$(function() { $(".numbers-row").append('<div class="buybutton dec">-</div><div class="buybutton inc">+</div>'); $(".buybutton").on("click", function() { var $button = $(this); var oldValue = $button.parent().find("input").val(); if ($button.text() == "+") { var newVal = parseFloat(oldValue) + 1; } else { // Don't allow decrementing below zero if (oldValue > 0) { var newVal = parseFloat(oldValue) - 1; } else { newVal = 0; } } $button.parent().find("input").val(newVal); }); });
August 1, 2013 at 10:40 pm #145452thechrisroberts
ParticipantYou have the jQuery code in your file incrementing.js and that file is being loaded twice, thus it is running twice. View the source of the page, you will see two lines like:
<script src="http://www.kattnakken.no/js/incrementing.js"></script>
It looks like other JavaScript is also showing up twice. I’m not sure what is powering your site, but the theme needs to be fixed so that it only inserts JavaScript once.
August 2, 2013 at 12:24 am #145455hoeiesta
ParticipantHi Chris,
Thank you!
It was my mistake. I probably copied the line with the script when I was duplicating a trigger for a popup.
Thanks for pointing out the other double scripts as well:-) -
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.