<div class="container">
  <h2><a href="https://markjs.io/" target="_blank">mark.js</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>
        <button type="button" class="btn btn-default btn-sm" name="perform">Perform</button>
        </div>
        <div class="col-xs-6">
          <div class="form-group">
            <label for="accuracy">Accuracy:</label>
            <select class="form-control input-sm" name="accuracy" id="accuracy">
              <option value="exactly">exactly</option>
              <option value="partially" selected>partially</option>
              <option value="complementary">complementary</option>
             </select>
          </div>
           <div class="form-group">
            <label for="element" class="noTransform">Element</label>
            <input type="text" class="form-control input-sm" value="mark" name="element" id="element">
          </div>
          <div class="form-group">
            <label for="className" class="noTransform">Class name</label>
            <input type="text" class="form-control input-sm" value="highlight" name="className" id="className">
          </div>
          <div class="form-group">
            <label for="diacritics" class="noTransform"><input type="checkbox" value="true" name="diacritics" id="diacritics" checked> diacritics</label>
          </div>
          <div class="form-group">
            <label for="separateWordSearch" class="noTransform"><input type="checkbox" value="true" name="separateWordSearch" id="separateWordSearch" checked> separate word search</label>
          </div>
        </div>
      </form>
      <strong>For a full list of methods and options visit the <a href="https://markjs.io/configurator.html" target="_blank">configurator</a></strong>
    </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 Lörem ipsum dolor sit amet. Lorem ipsüm 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;
  padding: 0;
}


/**
 * 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 $button = $form.find("button[name='perform']");
  var $input = $form.find("input[name='keyword']");

  $button.on("click.perform", function() {

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

    // Determine options
    var options = {};
    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.unmark();
    $context.mark(searchTerm, options);

  });
  $button.trigger("click.perform");
});

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://cdn.rawgit.com/julmot/mark.js/master/dist/jquery.mark.min.js