JQuery发现最接近兄弟div

时间:2011-02-07 12:03:19

标签: jquery

以下内容:

                    <div class="section">
                        <div class="row infoOn">
                            <div class="itemWrap clearfix">
                                <div class="itemTop clearfix">
                                </div>
                                <label class="">File title:</label>
                                <div class="inputWrap clearfix">
                                    <input type="text" class="text inpButton" value="upload file first" disabled="true"/>
                                    <a id="fileUpload" href="#" class="button">Browse</a>
                                </div>
                            </div>
                        </div>

                        <!-- filelist -->
                        <div class="row uploadList">
                            <div class="itemWrap clearfix">
                                <label>&nbsp;</label>
                                <div class="inputWrap clearfix" style="position:relative;">
                                    <ul>
                                        <li><span class="qq-upload-file">companyPic.png</span><span class="qq-upload-spinner"></span><span class="qq-upload-size" style="display: none;"></span><a href="#" class="qq-upload-cancel">Cancel</a><span class="qq-upload-failed-text">Failed</span></li>
                                        <li><span class="qq-upload-file">companyPic.png</span><span class="qq-upload-spinner"></span><span class="qq-upload-size" style="display: none;"></span><a href="#" class="qq-upload-cancel">Cancel</a><span class="qq-upload-failed-text">Failed</span></li>
                                        <li><span class="qq-upload-file">untitled.bmp</span><span class="qq-upload-spinner"></span><span class="qq-upload-size" style="display: none;"></span><a href="#" class="qq-upload-cancel">Cancel</a><span class="qq-upload-failed-text">Failed</span></li>
                                        <li><span class="qq-upload-file">This i...Document.docx</span><span class="qq-upload-spinner"></span><span class="qq-upload-size" style="display: none;"></span><a href="#" class="qq-upload-cancel">Cancel</a><span class="qq-upload-failed-text">Failed</span></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <!-- // file list -->
</div>

如何在“div.uploadlist”中选择'ul'元素

    var button = $('#fileUpload')[0];
    alert($(button).closest('div.row').find('.uploadList ul').html());

...

3 个答案:

答案 0 :(得分:8)

您可以使用例如$(button).closest('div.row').next('.uploadList').find('ul')

答案 1 :(得分:2)

var button = $('#fileUpload');
alert(button.closest('div.row').next("div.uploadList ul").html());

您不必获取HTML对象,然后将其再次包装到jQUery对象。

答案 2 :(得分:0)

将相应的infoOn和uploadList包装在自己的div中。在您的示例中可能是div.section。然后,找到div.infoOn的div.section父级并在该父级中找到uploadList。