jQuery – Dynamically swap out text or element on click

I love this snippet! I used it in this way: Say I have a tabbed list/slider but my tab header titles are running down the side of the page in a column. To bring more attention to which tab a user is on, I made a faux title at the top of the page where the title would dynamically swap out with the name of whichever tab the user had clicked on.

$("#nameoflist >li a").click(function (ev) {  //Every time a user clicks on a link in a list
       var _crumb = 'your-static-text ' + $(this).text();   //Append static text and/or dynamic text
       $('li.destination').text(_crumb);                    //to any given destination.. ie. li class='destination'
});

-credit to Larry for sharing this tip!

Leave a Reply