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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
About this lesson46s
-
(Locked)
Relocating the nav element4m 33s
-
(Locked)
Adding a mobile link button4m 43s
-
(Locked)
Removing the header height restrictions2m 2s
-
Restyling the mobile menu2m 22s
-
(Locked)
Adjusting the logo to overlap the menu3m 58s
-
(Locked)
Adding JavaScript and jQuery to your project5m 32s
-
(Locked)
Attaching a click event to the mobile menu button4m 4s
-
(Locked)
Animating the height of the navigation4m 51s
-
(Locked)
Removing the style attribute from the nav element5m 21s
-
(Locked)
Where to go from here25s
-
(Locked)
-
-