HTML looks like:
<dl> <dt> <img src='Images\Something\expand-close.gif' /> Something 1 </dt> <dd>Something 1 Text</dd> </dl>
This HTML is repeated 1 or more times, so there may be many instances of HTML on the same page.
The jquery that I use to expand dd and replace the image:
$("dl").find("dt").click(function() { // toggle the dd $(this).next().toggle(200); // replace the expand / close image var img = $(this).find("img"); var src = img.attr("src"); if (src.lastIndexOf("open.gif") != -1) { img.attr("src", src.replace("open.gif", "closed.gif")); } else { img.attr("src", src.replace("closed.gif", "open.gif")); } });
All this works great and does exactly what I need. My question is: can a jQuery function be executed better? I'm relatively new to using jQuery, and this was the snippet that I raked. If this could be done better, explain the changes as I am trying to learn how to write jQuery code. Any other pointers or suggestions would also be appreciated.
source share