search

Home  >  Q&A  >  body text

Rewrite the title to: From less information to more information: Auto-click to expand collapse links

I'm trying to use automation to display more information on click of a "more details" link on a popup, but the link doesn't have any id associated with it. When I inspect the link in the Chrome console, it appears to be the "href="#myCollapse"" line in the associated element below. I don't really understand js but tried something like document.getElementById('#myCollapse'). click();...and try to use the child with id="popup-content".

<div id="popup-content">
        <span id="overlayAddress">SCOTTISH PARLIAMENT  1 HORSE WYND OLD TOWN </span><br>
        <span id="overlayTown">EDINBURGH</span><br>
        <span id="overlayPostCode">EH99 1SP</span>
        <br>
            <a href="#myCollapse" data-bs-toggle="collapse" class="collapsed" aria-expanded="false">更多详情</a>
            <div class="collapse" id="myCollapse" style="">
             <label style="color:white;"><b>UPRN :&nbsp;</b></label><span id="overlayuprn">906423108</span><br> 
             <label style="color:white;"><b>POSTAL TOWN :&nbsp;</b></label><span id="overlayPostTown">EDINBURGH</span><br>
             <label style="color:white;"><b>CUSTODIAN :&nbsp;</b></label><span id="overlayCustodian">City of Edinburgh</span><br>
            </div>
        </div>

P粉037450467P粉037450467511 days ago554

reply all(1)I'll reply

  • P粉818306280

    P粉8183062802023-09-14 00:24:19

    Just use the following selector:

    document.querySelector('#popup-content a[href="#myCollapse"]').click()
    

    reply
    0
  • Cancelreply