innerHTML containing bookmarks cannot be linked to from another page

I use JavaScript AJAX to include a file cards.html into a parent html page index.html.
The included cards.html file is a list of cards and each card has a bookmark in it in the form <li id="byx-123_shapes">.
When I hyperlink to the bookmark from another page, instead of the browser positioning on the bookmark it positions on the top of the page.
If I manually insert cards.html into index.html the hyperlinking works properly.
It seems like the browser is unaware of the bookmarks because they were imported via AJAX rather than being there when index.html was loaded.

Cards.html included in index.html.

    <section id="cards">
    <!-- INSERT CARDS HERE -->
    <ul>
    <li id="byx-123_shapes" class="byx-book-tile byx-box">
    
        <figure>
            <img src="books/123_shapes/res/icon.png">
        </figure>
        
        <h2>
            123 Shapes
        </h2>
        <p>
            Placeholder for a book that is still being written.
        </p>
        <a href="previews/123_shapes_view.html">Preview Book</a>
    </li>

    .... more cards ...

    <li id="byx-zoo_friends" class="byx-book-tile byx-box">
        
        <figure>
            <img src="books/zoo_friends/res/icon.png">
        </figure>
        
        <h2>
            Zoo Friends
        </h2>
        <p>
            Placeholder for a book that is still being written.
        </p>
        <a href="previews/zoo_friends_view.html">Preview Book</a>
    </li>
    </ul>
    </section>
...

JavaScript to load cards.html

// Uses AJAX to load cards.html
// Works but messes up card bookmarks
const xhr = new XMLHttpRequest();
const cards = document.getElementById('cards');
xhr.onload = function() {
    if (this.status == 200) {
        cards.innerHTML = xhr.responseText;
    } else {
        console.warn('Could not load cards');
    };
};
xhr.open('get', 'cards.html');
xhr.send();

Example of a hyperlink that doesn’t work when include via AJAX but does work when insert cards manually.

https://...//index.html#byx-zoo_friends

Can someone explain why this happens and how to fix it.

88 thoughts on “innerHTML containing bookmarks cannot be linked to from another page”

  1. pharmacie ouverte jusqu’Г  21h therapies hypnotiques (patrick hygonnet) , pharmacie a avignon pharmacie grignon annecy le vieux , DГіnde comprar Modafinil 200 mg, DГіnde comprar Modafinil 200 mg. Comprar Modafinil sin receta Comprar Modafinil genГ©rico [url=https://kit.co/meorgaral/comprar-modafinil-sin-receta-donde-comprar-modafinil-200-mg#]Comprar Modafinil medicamento[/url] pharmacie autour de chez moi Comprar Zocor sin receta, DГіnde comprar Zocor 40 mg. Zocor en farmacia EspaГ±a Comprar Zocor genГ©rico [url=https://kit.co/pinphkeca/donde-comprar-zocor-40-mg-comprar-zocor-sin-receta#]Comprar Zocor medicamento[/url] , medicaments diabete pharmacie en ligne emla , therapie cognitivo-comportementale drummondville. pharmacie l’ensoleillee aix en provence king’s college therapies Colchicine en farmacia Colombia, DГіnde comprar Colchicine tableta. Comprar Colchicine sin receta Comprar Colchicine genГ©rico [url=https://kit.co/unarpig/comprar-colchicine-generico-colchicine-en-farmacia-colombia#]Colchicine Colchicine tableta[/url] , therapie jungienne. pharmacie de garde marseille ce jour, pharmacie de garde avignon pharmacie de garde boulogne billancourt 14 juillet . pharmacie leclerc mareuil les meaux, therapies used to treat cystic fibrosis pharmacie boticinal boulogne billancourt therapie comportementale et cognitive strasbourg .

    Reply
  2. 146806 147119Youre so correct. Im there with you. Your weblog is surely worth a read if anyone comes throughout it. Im lucky I did because now Ive obtained a entire new view of this. I didnt realise that this problem was so crucial and so universal. You totally put it in perspective for me. 730923

    Reply

Leave a Comment