I've successfully got the first Javascript code on this answer by @PSL to work, and created my own version (see below). The code basically changes the text within a button each time the button is clicked. But what I can't do is insert HTML into the button text. When I do this all it does is display the HTML code in the button text, rather than execute it. Please could someone tell me how to amend this Javascript below to allow HTML to be inserted into the Button text each time the button is clicked. Thank you!
For example I'm working with
Current HTML
<button id="viewPhotosButton" type="button" class="btn btn-large" data-toggle="collapse" data-target="#photos-slide"><i class="icon-align-left icon-chevron-down"></i> View More Photos</button>
Javascript
$(function(){
$('#viewPhotosButton').click(function(){
$(this).text(function(i,old){
return old=='<i class="icon-align-left icon-chevron-down"></i> View More Photos' ? '<i class="icon-align-left icon-chevron-up"></i> Hide Extra Photos' : '<i class="icon-align-left icon-chevron-down"></i> View More Photos';
});
});
});
Desired HTML for Button (after click) icon-chevron-down has changed to icon-chevron-up AND View More Photos has changed to Hide Extra Photos
<button id="viewPhotosButton" type="button" class="btn btn-large" data-toggle="collapse" data-target="#photos-slide"><i class="icon-align-left icon-chevron-up"></i> Hide Extra Photos</button>