From the course: Creating a Responsive Web Design: Advanced Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Attaching a click event to the mobile menu button

Attaching a click event to the mobile menu button - CSS Tutorial

From the course: Creating a Responsive Web Design: Advanced Techniques

Attaching a click event to the mobile menu button

- Now to enable the mobile menu button, we're going to use jQuery to assign a click event to the object. So back in our JavaScript file, let's come in here and delete the alert. And now we're going to use jQuery's capability to search and find elements in our HTML. So we'll do that by typing $(''). We're going to put a string inside of here, and we're going to search for the navigation element with the anchor tag in a class of mobile menu. So as I mentioned before, jQuery uses the same syntax as HTML and CSS for defining selectors, so what we'll do inside of this string is we'll type nav a.mobile_menu. So jQuery gets its name from the fact that it queries your HTML. So we're looking for a navigation element and then an anchor tag inside with a class of mobile_menu. Now outside of the parentheses we're going to type .on();. Now inside of this on function, we're going to define the event that we want to assign to the menu, and in this case it's going to be a click event. So…

Contents