javascript - Get Div class content html - Stack Overflow

How can I get content of div class="dpBibHoldingStatement" ?It can't be used with getEl

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>

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>
Share Improve this question edited Jun 17, 2013 at 9:10 Darren 70.9k24 gold badges141 silver badges145 bronze badges asked Mar 6, 2013 at 18:47 helloeveryonehelloeveryone 391 silver badge6 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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.

You can either use document.getElementsByClassName[n] to target the (n-1)th element on the page, or you attach an ID to it and use document.getElementById(id).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745493181a4630077.html

相关推荐

  • javascript - Get Div class content html - Stack Overflow

    How can I get content of div class="dpBibHoldingStatement" ?It can't be used with getEl

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信