This will do the trick. Note that you need to do the comparison within the terenary operator. If you just do "something" ? "blah" : "result
, it will always be true, because non-null values are always true.
var up = "../images/admin/Symbol_Up.png";
var down = "../images/admin/Symbol_Down.png";
$(".message_head").click(function(){
var icon = $(".icon[id=" + $(this).attr("id") + "]");
$(this).next(".message_body").slideToggle(500);
icon.attr("src", this.attr("src") == up ? down : up);
});
I just realized one fundamental issue with your HTML if your JavaScript css selector is accurate. You are asking for .icon[id=x] and using the ID attribute from the .message_head class to find the ID of the icon. For this to work, you would have to have the same ID for both, which is invalid HTML. What I imagine your HTML looks like is this:
<div class="message_head" id="1">
<img class="icon" src="up.jpg" id="1"/>
</div>
This is a nono. What you can do is this:
<div class="message_head" id="1">
<img class="icon" src="up.jpg" />
</div>
var up = "../images/admin/Symbol_Up.png";
var down = "../images/admin/Symbol_Down.png";
$(".message_head").click(function(){
var icon = $('.icon', this);
$(this).next(".message_body").slideToggle(500);
icon.attr("src", this.attr("src") == up ? down : up);
});