Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery find closest to sibling div

Tags:

jquery

for the following:

                    <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>

how do i select 'ul' element in "div.uploadlist" in relation to

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

??

like image 910
ShaneKm Avatar asked Feb 07 '11 12:02

ShaneKm


2 Answers

You could use e.g. $(button).closest('div.row').next('.uploadList').find('ul')

like image 129
ThiefMaster Avatar answered Sep 21 '22 05:09

ThiefMaster


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

You don't have to get the HTML object and then wrap again it to jQUery object.

like image 33
rahul Avatar answered Sep 21 '22 05:09

rahul