troubleshooting Question

list:contains ... search finds as it should but how could I get the number items found?

Avatar of Mark Branscum
Mark BranscumFlag for United States of America asked on
JavaScriptjQuery
3 Comments1 Solution120 ViewsLast Modified:
Here is my codepen   http://codepen.io/jsMarko/pen/qrGevG

What I am wondering is if I could have the number of items/names found?

$(document).ready(function() {
  $("#btn").click(function() {
    var sName = $("#nameSearch").val();
    $("li").removeClass('result');
    $("li:contains('" + sName + "')").addClass('result');

  });
  $("input[type='text']").click(function() {
    $(this).select();
  });
  var count = $("ol").children().length;
  $("#lab").text("# " + count);
});

Open in new window


.result {
  text-decoration: underline;
  Font-weight: bold;
  font-size: 20px;
}

#nameSearch {
  margin-left: 25px;
  margin-top: 10px;
  width: 194px;
}

#lab {
  float: right;
  padding: 5px 15px;
  font-weight: bold;
  color: #fff
}
#btn {
  margin-left: 5px;
}

.listHeader {
  position: absolute;
  background-color: #85a0ad;
  width: 180px;
  height: 30px;
}

ol {
  padding-top: 25px;
}

#bord {
  overflow: hidden;
  overFlow: auto;
  height: 140px;
  border: 1px solid gray;
  width: 185px;
  text-aligh: center;
  margin-left: 25px;
  padding-right: 10px;
  box-shadow: 5px 5px 2px #666;
  background-color: #c9e3ef;
}

Open in new window

<html lang="en">

<head>
  <meta charset="utf-8">
  <title>contains demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

</head>

<body>
  <div id="bord">
    <div class="listHeader">
    <label Id="lab">#</label>
    </div>
    
    <ol>
      <li>Bill Jones</li>
      <li>Cindy Nelson</li>
      <li>Katherine Gates</li>
      <li>David Johnson</li>
      <li>Steve Jobs</li>
      <li>Ricky Nelson</li>
      <li>David Jones</li>
      <li>Mary Smith</li>
      <li>Tim Conway</li>
      <li>Jerry Lewis</li>
      <li>Bobby McGee</li>
      <li>Danny Smith</li>
    </ol>
  </div>
  <input id="nameSearch" type="text" placeholder="Search Name" />
  <button id="btn">Search</button>


</body>

</html>

Open in new window

ASKER CERTIFIED SOLUTION
HainKurt
Sr. System Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 3 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 3 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004