---
title: "jquery 控制 insertBefore(content)"
author: "KAXU"
date: "2009-01-13T17:25:02Z"
tags: ["HTML", "jQuery"]
slug: "jquery-insertbefore-content"
draft: false
lastmod: "2009-01-13T17:25:02Z"
id: 315793
url: "https://kaxu.iteye.com/blog/315793"
---

insertBefore(content)

将匹配元素集合插入到匹配元素集合‘content’之前

```
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    $("p").insertBefore("#foo"); // check before() examples
  });
  </script>
  <style>#foo { background:yellow; }</style>
</head>
<body>
  <div id="foo">FOO!</div><p>I would like to say: </p>
</body>
</html>
```

 

$("p").insertBefore("#foo"); // check before() examples  
将匹配p元素集合插入到属性值为‘foo’的匹配元素之前。