Toggle element with loading icon
<p>What I want to do is when a user clicks a button, to change the image of the button to a loading icon.</p>

<p>My javascript function looks like this - </p>

<pre><code>function GenerateDetail() {
    var resBtn = $('ctl00_cpMain_cntnrRoot').find("btn_generateDetail");
    if (resBtn != null) {
        toggleElement(resBtn);
    }
}

function toggleElement(aRelEle) {
    if ($(aRelEle).css("display") != "none") {
        addImage(aRelEle);
        $(aRelEle).css("display", "none");
    }
    else {
        $(aRelEle).prev().remove();
        $(aRelEle).css("display", "inline");
    }
}

function addImage(aParEle) {
    var aImage = document.createElement("img");
    var aSrc = "App_Themes/Images/activityloader.gif";
    aImage.border = "0";
    aImage.src = aSrc;
    aParEle.appendChild(aImage);
}
</code></pre>

<p>In toggleElement, $(aRelEle).css("display") is undefined. Why? 'ctl00_cpMain_cntnrRoot' is a div I have around all of my elements on my page.</p>
