0

I'm trying to create a variable to is defined by a single attribute of a CSS class. Here's what I have now, which doesn't work.

var dist = $('.nav').css(width());

What I am trying to do: my script slides the .nav class upon click. The problem is, I'm using @media queries that change the width of .nav, which is the same value I need to slide. What I'm trying to do here is define the variable "dist" by the width attribute of .nav - then I could just input "dist" as the slide distance in the function.

This is probably a pretty simple thing that I'm just doing horribly wrong. Or perhaps there is a far simpler way to do it?

2
  • 1
    .css('width') or just .width() Commented Jan 14, 2014 at 15:51
  • downvoted for writing "any help is appreciated"... what a douche Commented Jan 16, 2014 at 20:41

1 Answer 1

2

You're calling width as though it were a function and then (if that worked) passing its return value into css. But unless your page defines one, there's no free-standing width() function (there is one on jQuery instances).

You either want to pass the string "width" into css, or call the jQuery width function:

var dist = $('.nav').css("width");
// or
var dist = $('.nav').width();
Sign up to request clarification or add additional context in comments.

1 Comment

cool that works. guess that's just a beginners mistake on my part. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.