jquery插入新的open close div

时间:2017-04-09 17:52:15

标签: javascript jquery html unwrap

我有一些菜单循环编码,如何在开始循环之前插入一些div,以及在结束循环之后插入一些div。我尝试使用.prepend但没有工作。

<li class="mega-menu-fullwidth dropdown"><a href='#'>Features</a>
    <ul class="dropdown-menu">
<!-- div open goes here <li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"> -->
            <!-- Start First Loop -->
            <a href='javascript:void(0);'>submega</a>
            <div class="col-md-3 equal-height-in">
            <ul class="list-unstyled equal-height-list">
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
            </ul>
            </div><!-- End First Loop -->
<!-- div close goes here </div></div></div></li> -->
    </ul>
</li>

任何可以帮助我吗?感谢

$(function(){ $('.mega-menu-fullwidth .dropdown-menu').prepend('<li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"></div></div></div></li>'); });

不工作。

1 个答案:

答案 0 :(得分:0)

希望它有所帮助。

&#13;
&#13;
<li class="mega-menu-fullwidth dropdown"><a href='#'>Features</a>
    <ul class="dropdown-menu">
<!-- div open goes here <li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"> -->
            <!-- Start First Loop -->
            <a href='javascript:void(0);'>submega</a>
            <div class="col-md-3 equal-height-in">
            <ul class="list-unstyled equal-height-list">
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
            </ul>
            </div><!-- End First Loop -->
<!-- div close goes here </div></div></div></li> -->
    </ul>
</li>
&#13;
&#13;
&#13;

&#13;
&#13;
var appendedHtml = '<li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif">'+$('ul.dropdown-menu').html()+'</div></div></div></li>';
$('ul.dropdown-menu').html(appendedHtml);

$('ul.equal-height-list').eq(0).find('li').eq(0).remove();
$('ul.equal-height-list').eq(0).prepend('<h3>One</h3>');
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<li class="mega-menu-fullwidth dropdown"><a href='#'>Features</a>
    <ul class="dropdown-menu">
<!-- div open goes here <li><div class="cfirst csecond"><div class="cthird"><div class="cfourt cfif"> -->
            <!-- Start First Loop -->
            <a href='javascript:void(0);'>submega</a>
            <div class="col-md-3 equal-height-in">
            <ul class="list-unstyled equal-height-list">
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
            </ul>
            </div><!-- End First Loop -->
<!-- div close goes here </div></div></div></li> -->
    </ul>
</li>
&#13;
&#13;
&#13;