I have an ASP.NET repeater element I'm using as a clickable menu. I'm using jQuery to set the img src to indicate which item is currently selected. I have a solution that works, but I'm wondering if there's a more elegant way to use jQuery... my solution kind of feels like a workaround.
My HTML:
<div class="c_menuDiv">
<img src="images/check_white.jpg" id="img_check" class="cd_checkImage" width="20px" >
<asp:Label ID="lblIssuedTo" runat="server" Text='<%#Bind("IssuedTo")%>'>
</asp:Label>
</div>
And my jQuery, on document-ready:
$('.c_menuDiv').each(function() {
issuedToBox = $('#txt_issuedTo').val(); <<== FROM A TEXTBOX
issuedToMenu = $(this).children("span").html();
if (issuedToBox == issuedToMenu ){
$(this).find('img:first').attr('src','images/check_selected.jpg');
}
})
My question is, is there a more elegant way to use jQuery and avoid that js IF statement? I ask only because I'd like to sharpen my jQuery skills.
Thanks for any advice.