比如可能实现如下API
$("#b").appendTo($("#a"),'top');
<div id="a">
  <div id="不定"></div>
  .
  .
  .
  <div id="不定n"></div>
</div>
<div id="b"></div>通过执行jq,html结构变为:<div id="a">
  <div id="b"></div>
  <div id="不定"></div>
  .
  .
  .
  <div id="不定n"></div>
</div>

解决方案 »

  1.   

    $("#a").prepend("#b");或者$("#b").prependTo("#a");
      

  2.   

    prepend 向每个匹配的元素内部前置内容。
    prependTo 把所有匹配的元素前置到另一个、指定的元素元素集合中。
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>测试层滚动</title>
    <script src="jquery-1.3.2.js"></script>
    <script>
    $(document).ready(function(){
    $("#btn").click(function(){
    $("#test_p").prepend("<b>hello</b>");//结果为 <p><b>Hello</b>I would like to say: </p>
    $("#test").prependTo("#foo");//结果为<div id="foo"><p>I would like to say: </p></div>
    });
    });
    </script>
    </head><body>
    <p id="test_p">I would like to say: </p> 
    <input type="button" id="btn" /><br />
    <p id="test">I would like to say: </p><div id="foo"></div> 
    </body>
    </html>
      

  4.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>测试层滚动</title>
    <script src="jquery-1.3.2.js"></script>
    <script>
    $(document).ready(function(){
    $("#btn").click(function(){
    $("#test_p").prepend("<b>hello</b>");//结果为 <p><b>Hello</b>I would like to say: </p>
    $("#test").prependTo("#foo");//结果为<div id="foo"><p>I would like to say: </p></div>
    });
    });
    </script>
    </head><body>
    <p id="test_p">I would like to say: </p> 
    <input type="button" id="btn" /><br />
    <p id="test">I would like to say: </p><div id="foo"></div> 
    </body>
    </html>