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
$(document).ready(function(){ $("#searchBar").click(function(){ $("#searchPredict").popover({ title: "testing123" }); }); });
Any ideas where I’m going wrong? Thanks in advance.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Adding $('#searchPredict').attr('data-bs-original-title', "testing123");
after your popover function.
$(document).ready(function(){
$("#searchBar").click(function(){
$("#searchPredict").popover();
//Bootstrap below 5
// $('#searchPredict').attr('data-original-title', "testing123");
//Bootstrap 5+
$('#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/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="nofollow noreferrer noopener" 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>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0