Close

Miscellaneous jQuery Snippets

Add Active Navigation Class to Menu Item Based on URL Using jQuery

In this jQuery tutorial, you’ll learn how to add an active class to a menu item based on the page URL using jQuery… so you can highlight that menu item. You’ll learn:

  • how use the jQuery addClass() method
  • how to get the current page’s URL path in JavaScript
  • how to split a URL in an array of parts
  • how to use the JavaScript pop() method
  • how to target an element based the value of a specified attributed using jQuery

Watch the tutorial below:

Links mentioned in the video:

Here’s the code I used in the video:

https://gist.github.com/b522257ae204d95ebcbe

If you get value from this code snippet, please consider sharing it with another developer or group who could benefit from it.

September 20, 2015

Set DIV Height to 100% of Its Parent Using jQuery

In this jQuery tutorial, you’ll learn how to set the height of a DIV to 100% of its parent. You’ll learn:

  • how to set variables and target selectors
  • how to get and set div height using height()
  • how to target multiple selectors at once

Watch the tutorial below:

Links mentioned in the video:

Here’s the code I used in the video:

https://gist.github.com/2fcdced608ea814f51c1

If you get value from this code snippet, please consider sharing it with another developer or group who could benefit from it.

September 11, 2015

jQuery Tutorial: How to Build a jQuery Accordion

In this jQuery tutorial, you’ll learn how to build a jQuery accordion. You’ll learn:

  • how to slideUp() and slideDown() different elements
  • how to use relative selectors to target elements in jQuery
  • how to use the click event to trigger functionality on click

Watch the tutorial below:

Links mentioned in the video:

Here’s the code I used in the video:

https://gist.github.com/89c97a7832b4f2b338a4

If you get value from this code snippet, please consider sharing it with another developer or group who could benefit from it.

September 6, 2015