Check if the jQuery object contains any element before you try to get its offset:
var nav = $('.content-nav');
if (nav.length) {
var contentNav = nav.offset().top;
...continue to set up the menu
}
Related Contents:
- Retrieve the position (X,Y) of an HTML element
- Height equal to dynamic width (CSS fluid layout) [duplicate]
- Make header and footer files to be included in multiple html pages
- Check if an element contains a class in JavaScript?
- What is the most efficient way to create HTML elements using jQuery?
- jQuery: Get height of hidden element in jQuery
- Cross-browser multi-line text overflow with ellipsis appended within a fixed width and height
- Changing CSS Values with Javascript
- How do I create a link using javascript?
- Can I use HTML tags in the options for select elements? [duplicate]
- Finding line-wraps
- How to get the element clicked (for the whole document)?
- Keep overflow div scrolled to bottom unless user scrolls up
- Clear icon inside input text
- Animate element to auto height with jQuery
- Why are duplicate ID values not allowed in HTML?
- Show and hide divs at a specific time interval using jQuery
- Is there a DOM event that fires when an HTML select element is closed?
- How to connect HTML Divs with Lines? [duplicate]
- Dynamically loading css stylesheet doesn’t work on IE
- How to silently hide “Image not found” icon when src source image is not found
- How to get nth-child selector to skip hidden divs [duplicate]
- Hide scrollbar while still being able to scroll with mouse/keyboard [duplicate]
- Infinity Loop Slider Concepts
- How to find a parent with a known class in jQuery?
- How can I remove the “No file chosen” tooltip from a file input in Chrome?
- focus doesn’t work in IE
- Text blinking jQuery
- width/height after transform
- Disable dragging an image from an HTML page
- Responsive horizontal page sliding
- Show text letter by letter
- Can I apply CSS to the elements within an iframe?
- How to keep the menu state on page reload
- jQuery vs document.querySelectorAll
- scrollTop animation without jquery [duplicate]
- Center flex item in container, when surrounded by other flex items
- Save a pre element as PDF with CSS
- how to disable DIV element and everything inside [duplicate]
- How to open specific tab of bootstrap nav tabs on click of a particuler link using jQuery?
- How do I make a move up and down when I’m scrolling the page?
- CSS Textarea that expands as you type text [duplicate]
- Load HTML page dynamically into div with jQuery
- jQuery position DIV fixed at top on scroll
- How to define the css :hover state in a jQuery selector?
- I want to show list items as 2 or more columns (dynamic alignment)
- Convert dropdown to selection boxes with color and trigger drop down action
- Set focus and cursor to end of text input field / string w. Jquery [duplicate]
- Open new window without focus on it [duplicate]
- How to show hidden divs on mouseover?