- $("a.more_info").toggle(function(){
- var itemid = $(this).parent().parent().parent().parent().attr('id');
- var itemid_hash = "#" + itemid + " .details_exp";
- var itemid_tog_more = "#" + itemid + " a.more_info"; $(itemid_tog_more).addClass("less_info").removeClass("more_info");
- $(itemid_hash).fadeIn();
- }, function () {
- var itemid = $(this).parent().parent().parent().parent().attr('id');
- var itemid_hash = "#" + itemid + " .details_exp";
- var itemid_tog_less = "#" + itemid + " a.less_info";
- $(itemid_tog_less).addClass("more_info").removeClass("less_info");
- $(itemid_hash).fadeOut();
- });
First, is there a way to go up four levels in the DOM without stacking up .parent() four times?
Second, is there a better way to define the "itemid" and "itemid_hash" variables so I don't have to redefine them for the second half of the toggle function?
The code is working great as is, but I just want to make sure I've doing things in the most correct way.
Thanks!