Reputation: 525
I have used Bootstrap popovers and in this one, I'd like to add an href="somelink". But this seems impossible to do with the current code situation:
<a
tabindex="0"
class="btn btn-link"
role="button"
data-toggle="popover"
data-trigger="focus"
title="Reaction Time (s)"
data-content="Enter the time it takes for a driver to react.
Reaction times vary with age, distractions, alcohol or drug usage etc.
The unit is seconds.">
<i class="far fa-question-circle fa-2x"></i>
</a>
What do I need to do to get an href into that popover text?
Upvotes: 2
Views: 2643
Reputation: 307
Do you need this?
$("#testpopover").popover({
html: true,
title:"React time(s)",
content: "Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum."+
"<a class='btn btn-default'>HTML in popover</a>"
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div style="width:100%; height:500px; margin-top:15%">
<a type="button" class="btn btn-default" id="testpopover">popover</a>
</div>
Upvotes: 0
Reputation: 20039
Try setting options html
as true
and sanitize
as false
https://getbootstrap.com/docs/4.3/getting-started/javascript/#sanitizer
$('[data-toggle="popover"]').popover({
sanitize: false
})
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<a tabindex="0" class="btn btn-link" role="button" data-toggle="popover" data-html="true" data-trigger="focus" title="Reaction Time (s)" data-content="Enter the time it takes for a driver to react.
Reaction times vary with age, distractions, alcohol or drug usage etc.
The unit is seconds. <a href='https://stackoverflow.com/'>Go</a>">
<i class="far fa-question-circle fa-2x"></i>?
</a>
Upvotes: 0
Reputation: 28522
You need to pass html:true
while initializing your popover.
Demo Code :
$(function () {
$("[data-toggle=popover]").popover({html:true})//add html as true to use html
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<a tabindex="0" class="btn btn-link" role="button" data-toggle="popover" data-trigger="focus" title="Reaction Time (s)" data-content="Enter the time it takes for a driver to react.
Reaction times vary with age, distractions, alcohol or drug usage etc.
The unit is seconds <a href='yoururl'>something</a>.">
<i class="far fa-question-circle fa-2x">Click</i>
</a>
Also check this for more information.
Upvotes: 1