<div class="container">
  <h2><a href="http://www.jquery.info/spip.php?article50" target="_blank">SearchHighlight</a> demo</h2>
  <div class="panel panel-default">
    <div class="panel-heading">
      <form class="row">
        <div class="col-xs-6">
          <div class="form-group">
            <label for="keyword">Search term:</label>
            <input type="text" class="form-control input-sm" value="Lorem" name="keyword" id="keyword">
          </div>
          Unfortunately this plugin does not offer a function to remove highlights, so you can not change the search term dynamically.
        </div>
        <div class="col-xs-6">
          <div class="form-group">
            <label for="exact">exact:</label>
            <select class="form-control input-sm" name="exact" id="exact">
              <option value="exact">exact</option>
              <option value="partial" selected>partial</option>
              <option value="whole">whole</option>
             </select>
          </div>
          <div class="form-group">
            <label for="style_name" class="noTransform">style name</label>
            <input type="text" class="form-control input-sm" value="highlight" name="style_name" id="style_name">
          </div>
          <div class="form-group">
            <label for="style_name_suffix" class="noTransform"><input type="checkbox" value="true" name="style_name_suffix" id="style_name_suffix"> style name suffix</label>
          </div>
        </div>
      </form>
    </div>
    <div class="panel-body context">
      <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
        takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores
        et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
    </div>
    <div class="panel-footer">This example is part of the article <a href="http://www.sitepoint.com/10-jquery-text-highlighter-plugins/" target="_blank">10 jQuery Text Highlighter Plugins</a> on <a href="http://sitepoint.com/" target="_blank">SitePoint</a> by <a href="https://github.com/julmot"
        target="_blank">Julian Motz</a>.</div>
  </div>
</div>
/**
 * Highlight any element inside the context
 * because it can be freely defined
 */
.context :not(p) {
  background: #f1c40f;
}


/**
 * The following is not related to the plugin
 */
body {
  background: #fbfcfc;
}

.container {
  max-width: 700px;
}

.form-group {
  margin-bottom: 5px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
}

.form-group label.noTransform {
  text-transform: none;
}
$(function() {
  var $context = $(".context");
  var $form = $("form");
  var $input = $form.find("input[name='keyword']");

  // Determine search term
  var searchTerm = $input.val();

  // Determine options
  var options = {
    "keys": searchTerm
  };
  var values = $form.serializeArray();
  /* Because serializeArray() ignores unset checkboxes */
  values = values.concat(
    $form.find("input[type='checkbox']:not(:checked)").map(
      function() {
        return {
          "name": this.name,
          "value": "false"
        }
      }).get()
  );
  $.each(values, function(i, opt) {
    var key = opt.name;
    var val = opt.value;
    if (key === "keyword" || !val) {
      return;
    }
    if (val === "false") {
      val = false;
    } else if (val === "true") {
      val = true;
    }
    options[key] = val;
  });

  // Remove old highlights and highlight
  // new search term afterwards
  $context.SearchHighlight(options);

});

External CSS

  1. https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/sandstone/bootstrap.min.css

External JavaScript

  1. https://code.jquery.com/jquery-2.2.3.js
  2. https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js
  3. https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/SearchHighlight.js