Javascript 如何使用jQuery通过Id查找特定的父级,并通过特定类获取其特定子级的值

Javascript 如何使用jQuery通过Id查找特定的父级,并通过特定类获取其特定子级的值,javascript,jquery,html,parent,children,Javascript,Jquery,Html,Parent,Children,我有一个动态div <div class="illustartionWrap" id="illustartionWrapId"> <div class="illusList illusListTop" id="illusList_heading"> <span class="fileName">File Name</span> <span class="fileDesc">Des

我有一个动态div

<div class="illustartionWrap" id="illustartionWrapId">
     <div class="illusList illusListTop" id="illusList_heading">
            <span class="fileName">File Name</span>
            <span class="fileDesc">Description</span>
            <span class="fileSize">File Size</span>
            <span class="fileDownload">Download</span>
    </div>
    <div class="clear"></div>
    <div class="illusList">
            <span class="fileName">fileTitle</span>
            <span class="fileDesc">fileDesc</span>
            <span class="fileSize">1.18 MB</span>
            <span class="fileDownload">
                <a href="http://myfile/file.txt">
                    <img src="/sites/all/themes/petheme/images/myimage.png">
                </a>
                <a href="#">
                    <img id="illFile_6" class="illDeleteFile" src="/sites/all/themes/petheme/images/icons/deleteButton.png">//clicking it to delete the file from db 
                </a>
            </span>
        </div>
 </div>
我使用jQuery Parent()、Parents()和children()以及find()进行了检查,但是我大部分都没有定义,没有得到标题

如何做到这一点

您需要使用:

var illFileTitle = jQuery(this).closest(".illusList").find(".fileName").text();

alert(illFileTitle);
看这个,

jQuery(".illDeleteFile").on("click", function() {
    var illFileTitle =jQuery(this).closest(".illusList").find(".fileName").html();
    alert (illFileTitle);
});

在您的示例中,我没有看到任何
filetitle
classed元素?
。。。很抱歉弄糊涂了。好问题。对我来说,这好像是一只虫子。但是,由于id在文档中应该是唯一的,
$(“#id”)
在这种情况下也可以使用。@hitesh因为id为
illusList\u标题的元素不是第二行的父元素;它是第一行的父级。请尝试
.closest(“#IllustrationWrapid”)
jQuery(".illDeleteFile").on("click", function() {
    var illFileTitle =jQuery(this).closest(".illusList").find(".fileName").html();
    alert (illFileTitle);
});