繁体   English   中英

如何使用jQuery通过ID查找特定的祖父母并通过某些类获取其特定孩子的价值

[英]How to find a particular grand parent by Id and get value of its particular children by certain class using jQuery

我有一个动态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>

如何获取此删除按钮的父对象并找到filetitle类以获取文件的标题。

下面是我写的点击处理程序

/**delete function for my page**/
    jQuery(".illDeleteFile").on("click", function() {
        var illDeleteId = jQuery(this).attr("id").split("_");
        var illFileTitle = jQuery(this).parent("#illusList").children(".fileName").val();

        alert (illFileTitle);
});

我用jQuery Parent(),Parents()和children()以及find()进行了检查,但是我得到的大多是未定义的,而且没有标题。

如何实现呢?

JSFIDDLEhttp : //jsfiddle.net/hiteshbhilai2010/ywhbd9ut/14/

您将要使用:

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);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM