Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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>Selecting Partial Attribute Names</h1>
<h2>using Xpath</h2>

<p>Selecting elements based on partial attribute name match isn't something CSS or JavaScript are equipped to do, but it <em>is</em> something which XPath is able to select fairly easily!</p>
<p>Below we have two examples of tags with custom attribute names, and if we wanted to select them in CSS or JavaScript we would have no way other than using the CSS selector <code>data-custom-1, data-custom-2</code>. But we can only write selectors like this if we know all of the custom attributes that might show up.</p>
<p>By using XPath with the following selector: <code>//*[@*[starts-with(name(), "data-custom-")]]</code> we are able to select all tags whose attributes begin with <code>data-custom-</code></p>

<h2>Demo:</h2>
<div data-custom-1>custom 1</div>
<div data-custom-2>custom 2</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                var tags = document.evaluate('//*[@*[starts-with(name(), "data-custom-")]]', document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null)

try {

  var node = tags.iterateNext()

  while (node) {

    node.style.color = 'black'
    node.style.background = 'lime'

    node = tags.iterateNext()
  }

}

catch (e) {
  console.log('couldn\'t style ' + e)
}
              
            
!
999px

Console