[ jquery 文档处理 insertAfter(content) after(content|fn) ] 此方法用于把所有匹配的元素插入到另一个、指定的元素元素集合的后面,实现外部插入

 

after(content | fn):在每个匹配的元素之后插入内容

insertAfter(content):

  把所有匹配的元素插入到另一个、指定的元素元素集合的后面

  实际上,使用这个方法是颠倒了常规的$(A).after(B)的操作,即不是把B插入到A后面,而是把A插入到B后面

  在jQuery 1.3.2中,appendTo, prependTo, insertBefore, insertAfter, 和 replaceAll这个几个方法成为一个破坏性操作,要选择先前选中的元素,需要使用end()方法,参见 appendTo 方法的例二

实例:

<html lang='zh-cn'>
<head>
<title>Insert you title</title>
<meta http-equiv='description' content='this is my page'>
<meta http-equiv='keywords' content='keyword1,keyword2,keyword3'>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type='text/javascript' src='./js/jquery-1.12.1.min.js'></script>
<style type="text/css">
    *{margin:0;padding:0;}
    html{font:400 15px/1.2em 'Courier New';color:#666;width:750px;margin:25px auto;}
    ul{list-style:none;}
    .hover{color:#FF96EC;}
</style>
<script type='text/javascript'>
    $(function(){

        $('.active').after($('#append'));
        $('p').insertAfter($('.active'));
    });
</script>
</head>
<body>
    <div id='demo'>
        <div class='noClassDemo'>
            <ul class='list'>
                <li>Index value :</li>
                <li>Index value :</li>
                <li>Index value :</li>
                <li>Index value :</li>
                <li>Index value :</li>
                <li>Index value :</li>
                <li class='active'>Index value :</li>
                <li>Index value :</li>
                <li>Index value :</li>
            </ul>
            <div id='append'></div>
            <p class='p'>haha</p>
        </div>
    </div>
</body>
</html>

 

posted @ 2016-06-26 17:53  窗棂  Views(344)  Comments(0Edit  收藏  举报