I have popover with data attributes in every element
Here is snippet
$("[data-toggle=popover]").popover({
html: true,
content: function() {
var content = $(this).attr("data-popover-content");
return $(content).children(".popover-body").html();
},
title: function() {
var title = $(this).attr("data-popover-content");
return $(title).children(".popover-heading").html();
}
});
$('.mainnav').on('click', '.popover-content a', function() { // change this
let lang = $(this).data("lang")
console.log(lang);
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="mainnav">
<ul class="topnav">
<a href="#" data-toggle="popover" data-popover-content="#a1">Popover</a>
</ul>
</nav>
<div id="a1" class="hidden">
<div class="popover-heading">_('Välj ditt språk')</div>
<div class="popover-body">
<div>
<a href="#" data-lang="no">Norsk</a>
</div>
<div>
<a href="#" data-lang="de">Deutsch</a>
</div>
<div>
<a href="#" data-lang="nl">Nederlands</a>
</div>
<div>
<a href="#" data-lang="es">Español</a>
</div>
<div>
<a href="#" data-lang="dk">Dansk</a>
</div>
</div>
</div>
I need to get data-lang attribute and change the domain of the website. for example, it was http://local.test.dk:3000/# and if I choose Norsk, I need to redirect to http://local.test.no:3000/#
Getting data attribute is done, and how I can change link correctly?
Thank's for help.