Mario Bruscella Mario Bruscella - 9 days ago 7
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

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 this.id. It is an existing Element property.

Comments