Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bootstrap 5 Popover dynamic text

I’m trying and failing to set the text on a bootstrap popover:

HTML

<span class="d-inline-block" id="searchPredict" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" title="Search" data-bs-placement="bottom" data-bs-content="initial text">
    <input type="text" id="searchBar" class="form-control mr-sm-2" placeholder="Product search" aria-label="Product search" aria-describedby="basic-addon2" id="floatingInput2" name="searched">
</span>

JS

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$(document).ready(function(){
    $("#searchBar").click(function(){
        $("#searchPredict").popover({
            title: "testing123"
        });
    });
});

Any ideas where I’m going wrong? Thanks in advance.

>Solution :

Adding $('#searchPredict').attr('data-bs-original-title', "testing123"); after your popover function.

$(document).ready(function(){
    $("#searchBar").click(function(){
        $("#searchPredict").popover();
        $('#searchPredict').attr('data-bs-original-title', "testing123");
    });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>

<span class="d-inline-block" id="searchPredict" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="initial text">
    <input type="text" id="searchBar" class="form-control mr-sm-2" placeholder="Product search" aria-label="Product search" aria-describedby="basic-addon2"  name="searched">
</span>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading