html - Changing Image and Text Dynamically Javascript -
currently have translation script built website.
my problem activating , changing image , text selected language.
this current code:
<div class="btn-group"> <button type="button" class="btn dropdown-toggle" data-toggle="dropdown"> <img src="images/flag/united-kingdom.png" alt=""> english <span class="fa fa-bars"></span> </button> <ul class="dropdown-menu" role="menu"> <li><a href="#"><img src="images/flag/germany.png" alt=""> deutsch</a></li> <li><a href="#"><img src="images/flag/france.png" alt=""> français</a></li> <li><a href="#"><img src="images/flag/spain.png" alt=""> español</a></li> <li><a href="#"><img src="images/flag/nederlands.png" alt=""> nederlands</a></li> </ul> </div>
how change current language selection image 1 have selected?
if need more info i'll happy give it.
take image source , text of clicked item , replace button content it
$('.dropdown-menu a').click(function(){ $('.dropdown-toggle').html( $(this).html() + '<span class="fa fa-bars"></span>'); });
or without jquery
html
<a href="#" onclick="changedefault(this)"><img src="images/flag/germany.png" alt="" > deutsch</a>
js
function changedefault(item) { var button = document.getelementsbyclassname('dropdown-toggle')[0] button.innerhtml = item.innerhtml + '<span class="fa fa-bars"></span>'; }
Comments
Post a Comment