1

我有一个<ul>看起来像这样的

<ul class="class_1 class_2">
    <li class="class1">
        <div class="submission_list_item">
            <div class="sub_list_item_content modal_link" href="url here">
                <div class="facebook_user" style="display:none;"></div>
                <div class="submission_response ">
                    <label></label>
                    <span class="MediaUploadResponse"><img alt="Sample_mpeg4" src="url here"></span> </div>
                <div class="submission_response name">
                    <label>NAME:</label>
                    <span class="Response"></span> </div>
                <div class="submission_response last_name">
                    <label>LAST NAME</label>
                    <span class="Response"></span> </div>
                <div class="submission_response description">
                    <label>DESCRIPTION:</label>
                    <span class="Response"> Test </span> </div>
                <div class="submission_response video_title">
                    <label>VIDEO TITLE:</label>
                    <span class="Response"> Video </span> </div>
            </div>
        </div>
    </li>
    <li class="class1">
        <div class="submission_list_item">
            <div class="sub_list_item_content modal_link" href="url here">
                <div class="facebook_user" style="display:none;"></div>
                <div class="submission_response ">
                    <label></label>
                    <span class="MediaUploadResponse"><img alt="Sample_mpeg4" src="url here"></span> </div>
                <div class="submission_response name">
                    <label>NAME:</label>
                    <span class="Response"></span> </div>
                <div class="submission_response last_name">
                    <label>LAST NAME</label>
                    <span class="Response"></span> </div>
                <div class="submission_response description">
                    <label>DESCRIPTION:</label>
                    <span class="Response"> Test </span> </div>
                <div class="submission_response video_title">
                    <label>VIDEO TITLE:</label>
                    <span class="Response"> Video </span> </div>
            </div>
        </div>
    </li>
</ul>

我想要做的是交换 2 个 div 的顺序,名称和标题在我页面上的每个 <li> 项目中。在 <li> 上尝试了 .each 但没有运气。知道怎么做吗?

4

1 回答 1

3

我认为你需要这样的东西:

$('ul.class_1 li.class1').each(function() {
  var name = $(this).find('div.name');
  var video_title = $(this).find('div.video_title');
  name.insertAfter($('div.description', this));
  video_title.insertBefore($('div.last_name', this));
});

演示

于 2012-05-24T14:46:47.850 回答