简体   繁体   中英

Get Div class content html

How can I get content of div class="dpBibHoldingStatement" ? It can't be used with getElementByClass, because there are several same classes in the html. I can't show all the code.

<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&amp;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&amp;suite=pearl">
                        Gallo, Carmine.</a>
</div>
<div class="dpBibHoldingStatement">
    Circulation Collection&nbsp;
    HF5415.5 .G356 2012  &nbsp;
    DUE 10-03-13OFF CAMPUS&nbsp;
    &nbsp;
</div>

Give the div an ID and use innerHTML :

 <div id="yourDiv">
     Content
 </div>

Then using JavaScript do:

 var contents = document.getElementById("yourDiv").innerHTML;
 alert(contents);

First of all, it's not getElementByClass . It's getElementsByClassName .

When you run document.getElementsByClassName("label-key") on this page at developer tools, it'll show you an array of label-key items. You can get any item that you want from that array.

您可以使用document.getElementsByClassName[n]来定位页面上的第(n-1)个元素,或者为其附加一个ID并使用document.getElementById(id)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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