tags:

views:

35

answers:

2

How can I do this:

I have a CHECKMARK image wherein when I click that image, it will be replaced with a LOCK image. How can I do this in jquery and php?

+1  A: 

Could use a bit more context, but something like this:

$(function ()
{
    $('#checkmarkImage').click(function ()
    {
        $(this).attr('src', '/path/to/lock/image.jpg');
    });
});
Matt Ball
+4  A: 
$('img.checkmark').toggle(function() {
   $(this).attr('src', 'lock.png');
}, function() {
   $(this).attr('src', 'checkmark.png');
});

All img tags with the checkmark class will now have the toggle functionality:

<img src="checkmark.png" class="checkmark"/>
Jacob Relkin
+1 for `.toggle()`
Marko
So with this, after turning the CHECKMARK image to LOCK, if I click the LOCK image will it convert back to CHECKMARK?
anonymous2
@anonymous2, Yes.
Jacob Relkin
After converting it to lock image, it won't convert back to checkmark. Why is this so?
anonymous2
@anonymous2, Post your code please.
Jacob Relkin
function startproject(id) { $('img.proj_status').toggle(function() { if($(this).attr("src") === "images/lock_closed.png"){ $(this).attr('src', 'images/lock_open.png'); window.location = "startproject.php?id="+ id +" } else { $(this).attr('src', 'images/lock_closed.png'); window.location = "startproject.php?id="+ id +" } }); }
anonymous2
<input type="button" name="Started" onclick="javascript:startproject(<? echo $rowcheck['id']; ?>)" />
anonymous2
it already works. thanks anyway!
anonymous2