[英]Get Div class content html
我怎樣才能獲得div class =“dpBibHoldingStatement”的內容? 它不能與getElementByClass一起使用,因為html中有幾個相同的類。 我無法顯示所有代碼。
<div class="dpBibTitle">
<!-- please read c1063106, c1063117, c1044421, c1060576a before changing title -->
<a id="recordDisplayLink2Component_0" href="/iii/encore/record/C__Rb4101617__Sapple__P0%2C1__Orightresult__X5?lang=eng&suite=pearl">
The Apple experience : the secrets of delivering insanely great customer service</a>
/ by Carmine Gallo
</div>
<div class="dpBibAuthor">
<!-- author -->
<a id="authorDisplayLinkComponent_0" href="/iii/encore/search/C__SGallo%2C+Carmine.__Orightresult?lang=eng&suite=pearl">
Gallo, Carmine.</a>
</div>
<div class="dpBibHoldingStatement">
Circulation Collection
HF5415.5 .G356 2012
DUE 10-03-13OFF CAMPUS
</div>
給div一個ID並使用innerHTML
:
<div id="yourDiv">
Content
</div>
然后使用JavaScript執行:
var contents = document.getElementById("yourDiv").innerHTML;
alert(contents);
首先,它不是getElementByClass
。 它是getElementsByClassName
。
當您在開發人員工具的此頁面上運行document.getElementsByClassName("label-key")
時,它將顯示一系列label-key
項。 您可以從該陣列中獲取所需的任何項目。
您可以使用document.getElementsByClassName[n]
來定位頁面上的第(n-1)個元素,或者為其附加一個ID並使用document.getElementById(id)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.