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

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

              
                <h3>
  .html()与.text()</h3>
<div class="left first-div">
  <div class="div">
    <a>:first-child</a>
    <a>第二个元素</a>
    <a>:last-child</a>
  </div>
  <div class="div">
    <a>:first-child</a>
    <a>第二个元素</a>
    <a>:last-child</a>
  </div>
</div>

<h4>显示通过html方法获取到的内容</h4>
<p></p>

<h4>显示通过text方法获取到的内容</h4>
<p></p>
              
            
!

CSS

              
                .left {
  width: auto;
  height: 120px;
}

.left div {
  width: 150px;
  height: 70px;
  padding: 5px;
  margin: 5px;
  float: left;
  background: #bbffaa;
  border: 1px solid #ccc;
}
a,
p {
  display: block;
}

              
            
!

JS

              
                //显示出html方法获取到的内容
//.html()是整个html文档结构
$("p:first").text($(".first-div").html());
//显示出text方法获取到的内容
//.text()是文本内容的合集
$("p:last").text($(".first-div").text());
//通过.text()方法替换文本内容
$(".left a:first").text("替换第一个a元素的内容");
//通过.html()方法替换html结构
$(".left div:first").text("整个div的子节点都被替换了");
//通过.text()的回调,获取原本的内容,修改,在重新赋值
$(".left a:first").text(function(idnex, text) {
  return "增加新的文本内容" + text;
});

              
            
!
999px

Console