Mario Bruscella Mario Bruscella - 1 year ago 64
jQuery Question

$('#'+$(this).attr('id')+' .js ul').slideToggle(120)

Is there a way to optimize this jquery line

$('#'+$(this).attr('id')+' .js ul').slideToggle(120)

just referring to $(this), and not retrieving the id of the element?

Answer Source

Find off of the element you already have.

$(this).find('.js ul').slideToggle(120);

Also for future note. You don't have to do $(this).attr('id');. You can simply do It is an existing Element property.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download