2017-02-23 81 views
-3

獲取H4元素文本

點擊按鈕類「瞭解更多,我想要得到的<h4>元素的文本:

image

+4

*代碼/標記*,而不是圖片*的代碼/標記。更多:http://meta.stackoverflow.com/q/285551/157247 –

+0

我不知道你需要什麼。你的問題是什麼?你有什麼嘗試?預期與實際結果是什麼? – Xufox

回答

0

試試這個,

$(document).on("click",".btn-red", function(){ 
    console.log($("h4.item-title").html()); 
}); 

試試看吧,這會工作。

+0

鑑於它存在於'​​'中,無論正確還是錯誤,都可能會有更多的行,在這種情況下這是不夠的。 –

0

您可以使用此

$("a.btn").click(function(event){ 
 
     event.stopPropagation(); 
 
     event.preventDefault(); 
 
     console.log($(event.currentTarget).closest("td").find("h4.title").text()); 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table> 
 
    <tr> 
 
    <td> 
 
     <h4 class="title">Test</h4> 
 
     <a class="btn" >Click me</a> 
 
    </td> 
 
    </tr> 
 
</table>

0

只是在腳本標記添加此標題下方的標籤。(u需要Jquery的腳本庫使用jQuery的功能)。

$(".btn-red").click(function(){ 

    console.log($("h4.item-title").text()); 

}); 
+0

只需將它添加到標題標記下的腳本標記中(需要使用jquery腳本庫來使用jquery函數)。 – rish