jQuery replaceWith

Letâs say you have a bunch of elements that under certain situations you want to replace with another element. jQueryâs replaceWith() function is perfect for that.

Here is an example of replacing all links with the class replace with a different link. The use case was finding certain buttons that say âApply Nowâ and replacing them with buttons that say âFinish your applicationâ. Since searching for âApply Nowâ wasnât perfect (the text and other links said it, too) I manually put in the replace class so I knew exactly which elements Iâd be selecting.

$( "a.replace" ).replaceWith( '"/application/" class="button arrow-right">Finish your applicationArchived Link' );

Want to perform this action if a cookie exists? Try using js-cookie:

$( document ).ready(function() { if (Cookies.get('cookiename')) { $( "a.replace" ).replaceWith( '"/application/" class="button arrow-right">Finish your applicationArchived Link' ); } else { // do nothing } });