Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,
I have the task to show the popover when click the content. i need to show the existing html content in Popover.

HTML
<html>
<head></head>
<body>
<div>sampe ref <a href="ref1" onclick="PopOverReference(this)">1</a> sampe data</div>
<div>sampe ref <a href="ref2" onclick="PopOverReference(this)">2</a> sampe data</div>
<div>sampe ref <a href="ref3" onclick="PopOverReference(this)">3</a> sampe data</div>
.
.
.
.
.
<div>
<div>reference</div>
<div class="Bib" id="ref1"> ref1 need to show in popover when click 1</div>
<div class="Bib" id="ref2"> ref2 need to show in popover when click 2</div>
<div class="Bib" id="ref3"> ref3 need to show in popover when click 3</div>
</body>
</html>


What I have tried:

I have tried with below javascript funtion in onclick wvent. its not working.

JavaScript
function PopOverReference(var refCit)
{
	var attrValue=refCit.getAttribute("href");
	var refs=document.body.getElementsByClassName("Bib");
	
	for(var r=0, n = refs.length; r < n; r++)
	{
		if(attrValue=r.getAttribute("id"))
		{
			var bindToMe = document.createElement('div')
			bindToMe.innerHTML = r.innerHTML;
			$('#target').popover({
			content: bindToMe,
			placement: 'bottom',
			html: true
			});
		}
	}
}
Posted
Comments
Richard Deeming 10-May-18 12:01pm    
Start by removing the var from your function's parameter - that's not valid Javascript.
function PopOverReference(refCit)

Then add a return false to your onclick attributes to prevent the browser from trying to follow the link:
onclick="PopOverReference(this);return false;"

To be semantically correct, the links should start with "#" to indicate that they're pointing to a fragment within the current page, rather than a different page:
<a href="#ref1" ...
Christian Graus 11-May-18 0:02am    
Consider telling us what you've tried AND WHAT HAPPENED. 'It doesn't work' is not an explanation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900