javascript - replace button text with .replaceWith() -


this not seeming work me jsfiddle

$(document).ready(function() {     $('.dropdown-menu>li>a').on("click", function() {         var buttontext = $(this).text();         $('.dropdown-toggle').replacewith(buttontext);     }); }); 

try following:

$(document).ready(function() {   $('.dropdown-menu > li > a').on("click", function() {     var buttontext = $(this).text();     $('.dropdown-toggle').text(buttontext);   }); }); 

your query selector incorrectly using dropdown instead of dropdown-menu. also, replacewith() replace entire element, it's best use .text() change inner text of button.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -