Creating variables for selectors


Hi all, I came across a more efficient way to toggle the onclick dropdown menu and hide the others.

// create a variable for the onclick menu
var thisMenu = $(this).find('.dropdown-menu');
if ($(thisMenu).css('display') === 'none') {

Just a quick question. Is it more conventional to store the variable as following or the way I did it?

var $thisMenu = $($(this).find('.dropdown-menu'));


Hey @bitrockstar88319,

I think that either method you used for the variable is fine, but I'm not a JavaScript expert. I do think there's an easier way to do it though, since jQuery is designed to make things like this very easy. This is the code I have inside my main function:

$('.dropdown').click(function() {

I hope this helps a little :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.