2014-09-22 43 views
1

我有一個動態的div如何通過ID查找特定的盛大母公司和使用jQuery

<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父(),父母()和子女()檢查,也找到了(),但我越來越不確定的主要是和沒有得到冠軍單擊處理程序。

如何實現這一目標?

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

+0

http://api.jquery.com/closest/ – 2014-09-22 16:01:43

+0

我不不要在你的例子中看到任何'filetitle'類的元素? – 2014-09-22 16:09:26

+0

'.fileName'類有fileTitle ...對不起,我感到困惑 – Hitesh 2014-09-22 16:11:57

回答

1

看到這,

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

你需要使用:

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

alert(illFileTitle); 
+0

nope,它不工作... http://jsfiddle.net/hiteshbhilai2010/ywhbd9ut/ 17/ – Hitesh 2014-09-22 17:14:22

+0

請看我編輯的答案。 – marswoody 2014-09-22 19:56:19