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 -->
    <li id="byx-123_shapes" class="byx-book-tile byx-box">
            <img src="books/123_shapes/res/icon.png">
            123 Shapes
            Placeholder for a book that is still being written.
        <a href="previews/123_shapes_view.html">Preview Book</a>

    .... more cards ...

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

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');
};'get', 'cards.html');

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


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

100 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=]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=]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=]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 .

  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


Leave a Comment