javascript - How to replace a Font Awesome icon within link text with a different icon on link click? -
i run wordpress website edited laypersons no coding ability. homepage consists of list of standard html links (all of globally styled css resemble button), link text of consists of font awesome icon shortcode , link title.
<a href="http://example.org/mypage/">[icon name="car"]link text</a>
for user add link homepage, need is--while in visual editor--select font awesome icon via tinymce menu, write link text, , select both icon , link text when creating link via tinymce "create link" button.
the font awesome shortcode above results in actual html being rendered this:
<a href="http://mylink.org/mypage/"><i class="fa fa-car"></i>link text</a>
my question: when link clicked, have whichever icon contained within link replaced spinning font awesome gear/cog icon while page transitioning link target, replacing link following:
<a href="http://mylink.org/mypage/"><i class="fa fa-cog fa-spin"></i></i>link text</a>
i cannot figure out how make happen. have tried many ways via jquery learning language , cannot seem figure out how it.
in meantime, have accomplished workaround inserting both icons , using :focus pseudoclass show , hide 1 or other after link clicked, solution not seem work on mobile , don't want have users have have insert both icons each time:
any solutions require individual making link manually add class shortcode/html not work. thank help!!
since tagged jquery, can add .click()
event:
// when link clicked $('a').click(function() { // if link contains icon if ( $(this).find('.fa').length ) { // remove icon $(this).find('.fa').remove(); // prepend spinner $(this).prepend('<i class="fa fa-cog fa-spin"></i>'); } });
here's fiddle.
Comments
Post a Comment