Is there a better, more jQuery-ish way of handling this image substitution?
var image = $(obj).children("img");
if ($(image).attr("src") == "Images/TreeCollapse.gif")
$(image).attr("src", "Images/TreeExpand.gif");
else
$(image).attr("src", "Images/TreeCollapse.gif");
You could do something like this
e.g
N.B in your question you do $(image) multiple times. Its better to cache the lookup in a var e.g var $image=$(obj).children("img"); then use the $image from there on in.
Possible alternatives:
Not really.
I know... extremely helpful answer. What you are doing is pretty succinct and I'm not so sure there would be anything to make it more "jQueryish" as you ask.
now depending on how you are iterating through this if you are doing it to multiple image instances, that is where there might be some jQuery optimizations.
Wow. Answers come flying in, don't they? All of the above would work, but you could try this for a one-liner (it's untested)...
Update: I've just tested this and it works, so would the person who voted it down care to explain why they did that?
More jQueryish? Maybe! Clearer? I'm not sure!
Why set a variable when it isn't needed?