cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container">
  <h2><a href="https://bartaz.github.io/sandbox.js/jquery.highlight.html" target="_blank">jquery.highlight</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="element">Element name:</label>
            <input type="text" class="form-control input-sm" value="span" name="element" id="element">
          </div>
          <div class="form-group">
            <label for="className">Class name:</label>
            <input type="text" class="form-control input-sm" value="highlight" name="className" id="className">
          </div>
          <div class="form-group">
            <label for="wordsOnly" class="noTransform"><input type="checkbox" value="true" name="wordsOnly" id="wordsOnly" checked="checked"> wordsOnly</label>
            <label for="caseSensitive" class="noTransform"><input type="checkbox" value="true" name="caseSensitive" id="caseSensitive"> caseSensitive</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 $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.unhighlight();
    $context.highlight(searchTerm, options);

  });
  $button.trigger("click.perform");
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console