Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Help to remember jQuery selectors I regularly mixup</h1>

<p>In the following examples the .hightlight class is toggled for matching elements on click to show the selection.</p>

<p><a href="https://api.jquery.com/">jQuery Docs are here</a>.</p>

<dl>
  <dt>.find()</dt>
  <dd>
    <a href="#target" id="target-find">&lt;a&gt;I use jQuery’s .find() selector to find all &lt;i&gt; elements which are my descendants &mdash; 
      <i>&lt;i&gt;Like me!&lt;/i&gt;</i>&lt;/a&gt;</a>
  </dd>
</dl>

<dl>
  <dt>.next()</dt>
  <dd>
    <a href="#target" id="target-next">&lt;a&gt;I use jQuery’s .next() selector to find my immediately following sibling I am looking for, in this case I want to find my next  &lt;brother&gt;.&lt;/a&gt;</a>
    <div class="brother">&lt;brother&gt;I am a sibling of that &lt;a&gt; above me.&lt;/brother&gt;</div>
    <div class="brother">&lt;brother&gt;I am also a sibling of &lt;a&gt;, but alas I am not .next() to &lt;a&gt; and for this, I am sad.&lt;/brother&gt;</div>
  </dd>
</dl>

<dl>
  <dt>.siblings()</dt>
  <dd>
    <a href="#target" id="target-siblings">&lt;a&gt;I use jQuery’s .siblings() selector to find all of the type of siblings I am looking for, in this case I want to find my &lt;sisters&gt;.&lt;/a&gt;</a>
    <div class="brother">&lt;brother&gt;I am a sibling and brother of that &lt;a&gt; above me.&lt;/brother&gt;</div>
    <div class="sister">&lt;sister&gt;I am a sibling and sister of that &lt;a&gt; above me.&lt;/sister&gt;</div>
    <div class="sister">&lt;sister&gt;I am a sibling and sister of that &lt;a&gt; above me.&lt;/sister&gt;</div>
    <div class="brother">&lt;brother&gt;I am a sibling and brother of that &lt;a&gt; above me.&lt;/brother&gt;</div>
    <div class="sister">&lt;sister&gt;I am a sibling and sister of that &lt;a&gt; above me.&lt;/sister&gt;</div>
  </dd>
</dl>

<dl>
  <dt>.closest()</dt>
  <dd>
    <section>
      <div>&lt;section&gt;&lt;div&gt;
        <a href="#target" id="target-closest">&lt;a&gt;I use jQuery’s .closest() selector to find my closest ancestor that matches what I am looking for, in this case a &lt;section&gt; element.&lt;/a&gt;</a>&lt;/div&gt;&lt;/section&gt;</div>
    </section>
  </dd>
</dl>

<dl>
  <dt>.first()</dt>
  <dd>
    <a href="#target" id="target-first">&lt;a&gt;I use jQuery’s .first() selector to find the first element in a set I'm looking for, in this case I want to find the first &lt;li&gt; in my sibling &lt;ul&gt;.&lt;/a&gt;</a>
    <ul>
      <li>First</li>
      <li>Second</li>
      <li>Third</li>
    </ul>
  </dd>
</dl>
              
            
!

CSS

              
                body {
  padding: 1em;
}
dl {
  background: #ddd;
  padding: 1em;
}
.highlight {
  background: #ff00ff;
}
              
            
!

JS

              
                $("#target-find").click(function() {
  $(this).find("i").toggleClass("highlight");
});

$("#target-next").click(function() {
  $(this).next(".brother").toggleClass("highlight");
});

$("#target-siblings").click(function() {
  $(this).siblings(".sister").toggleClass("highlight");
});

$("#target-closest").click(function() {
  $(this).closest("section").toggleClass("highlight");
});

$("#target-first").click(function() {
  $("#target-first + ul li").first().toggleClass("highlight");
});
              
            
!
999px

Console