Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable auto text highlight input?

Tags:

html

css

I have this https://codepen.io/anon/pen/RgQOWz

Put any value and when clicking the decrease/decrement repeatedly the input box text will highlight which is not what I want to happen.

I tried user-select: none but still doesn't take any effect.

 $(".increment").click(function() {
   var score1 = $(".score").val();
   score1++;
   $(".score").val(score1);
 });

 $(".decrement").click(function() {
   var score1 = $(".score").val();
   if (score1 == 0) {} else {
     score1--;
     $(".score").val(score1);
   }
 });

 $(function() {
   $('input').bind('focus', false);
 });
body {
  margin: 20px;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.prdin {
  text-align: center;
  background: #f5f5f5;
  width: 40px;
  border: 1px solid #ccc;
  border-top: 0px;
  margin: 20px;
}

.prdin div {
  display: flex;
  height: 37px;
  justify-content: center;
  align-items: center;
  border-top: 1px solid #ccc;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none -ms-user-select: none;
  user-select: none;
}

.prdin input {
  text-align: center;
  border: 0px;
  height: 100%;
  width: 100%;
  font-size: 18px;
  font-weight: bold;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<!-- For icon styles -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css" rel="stylesheet" />

<div class="prdin">
  <div class="increment">
    <i class="icon-arrow-up icons"></i>
  </div>
  <div id="input1">
    <input type="number" class="score" value="0">
  </div>
  <div class="decrement">
    <i class="icon-arrow-down icons"></i>
  </div>
</div>

<div class="prdin">
  <div class="increment">
    <i class="icon-arrow-up icons"></i>
  </div>
  <div id="input1">
    <input type="number" class="score" value="0">
  </div>
  <div class="decrement">
    <i class="icon-arrow-down icons"></i>
  </div>
</div>
like image 229
user7716943 Avatar asked Jun 30 '17 15:06

user7716943


People also ask

How do I turn off text selection highlighting?

You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.

How do I turn off input box suggestions?

Use the <input> tag with autocomplete attribute. Set the autocomplete attribute to value “off”.

How do I remove a placeholder border?

Use the :focus pseudo-class with the "no-outline" class to style the form fields that are focused by the user. To have clear fields in your forms, set the outline property to its "none" value, which is used to display no outline.


1 Answers

You can use user-select: none; on the divs to disable the selection/highlighting.

$(".increment").click(function() {
  var score1 = $(".score").val();
  score1++;
  $(".score").val(score1);
});

$(".decrement").click(function() {
  var score1 = $(".score").val();
  if (score1 == 0) {
  } else {
    score1--;
    $(".score").val(score1);
  }
});

$(function() {
  $("input").bind("focus", false);
});
body {
  margin: 20px;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.prdin {
  text-align: center;
  background: #f5f5f5;
  width: 40px;
  border: 1px solid #ccc;
  border-top: 0px;
  margin: 20px;
}

.prdin div {
  display: flex;
  height: 37px;
  justify-content: center;
  align-items: center;
  border-top: 1px solid #ccc;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.prdin input {
  text-align: center;
  border: 0px;
  height: 100%;
  width: 100%;
  font-size: 18px;
  font-weight: bold;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="prdin">
  <div class="increment">
    <i class="icon-arrow-up icons"></i>
  </div>
  <div id="input1">
    <input type="number" class="score" value="0">
  </div>
  <div class="decrement">
    <i class="icon-arrow-down icons"></i>
  </div>
</div>
like image 71
Michael Coker Avatar answered Sep 18 '22 01:09

Michael Coker