0
<tr class="list1Row#currRow mod 2#" id="job_list_#jc_id#_pjcid#jc_parent#">
    <td nowrap="nowrap" style="border-top:1px solid black; text-align:left; min-width:40px;">
        <cfset qTwokiloFavorite = application.JobControlDAO.FavoriteRead(jcid=twokilo_id,uid=#userid#)>
        <span id="job_fav_#jc_id#">
            <cfif qJcFavorite.recordcount GT 0>
                <img src="_images/star_filled.png" height="18px" width="18px" alt="Remove Favorite" style="cursor:pointer;" align="absmiddle" onclick="jc_deleteFavorite(#jc_id#);"/>
            <cfelse>
                <img src="_images/star_empty.png" height="18px" width="18px" alt="Make Favorite" style="cursor:pointer;" align="absmiddle" onclick="jc_saveFavorite(#jc_id#);"/>
            </cfif>
        </span>
    </td>
    ....other tds
</tr>
function tk_deleteFavorite(jcid)
{
    var sJcFav = "job_fav_" + jcid;
    var sEmptyStar = '<img src="_images/star_filled.png" height="18px" width="18px" alt="Remove Favorite" style="cursor:pointer;" align="absmiddle" onclick="jc_deleteFavorite(';
    sEmptyStar += jcid;
    sEmptyStar += ');"/>';

    showStatus('Removing Favorite ...');

    $j('#' + sJcFav + ' span').html(sEmptyStar);

    ajax call here to delete favorite association -- works
}

When the page loads, the favorite star is determined by a queried value so that is why I have an if statement in the span.
However, when a user clicks on the star_filled image, I need to replace that image with the star_empty image. I have tried to empty the span and replace that way, but cannot get it to replace.

I left off the ajax call which removes the association of the favorite because that part is working.

Al.G.
  • 4,327
  • 6
  • 31
  • 56
Lori
  • 13
  • 3
  • Possible duplicate of [jQuery change image src attribute](https://stackoverflow.com/questions/7425821/jquery-change-image-src-attribute) – Jonathan Laliberte Aug 31 '17 at 19:58
  • `$j('#' + sJcFav + ' span')` tries to get the `span` inside your `span`. I think it might have to be `$j('#' + sJcFav)`? – putvande Aug 31 '17 at 19:59

1 Answers1

0

This is what finally worked, just changing out the src and using same function for onclick with minor adjustments.

var img = $j('#' + sJcFav).find('img');
img.attr("src", img.attr("src").replace("star_filled", "star_empty"));

Lori
  • 13
  • 3