We help IT Professionals succeed at work.

HELP with undefined variable in my jquery??

Hi,

This was coming up undefined (in my web developer tools in firefox):

var slider = $("article.slider");
var right = ($(slider).css("right")).length - 2;
var left = ($(slider).css("left")).length - 2;

Open in new window


So I put these variables in an if statement because on another page they are needed.

   
var slider = $("article.slider");
if (slider) {
        var right = ($(slider).css("right")).length - 2;
        var left = ($(slider).css("left")).length - 2;
}

Open in new window


So basically I am trying to say if this element exists on the page (article.slider) then set these variables.  If not just ignore them. But they are still coming up undefined.  Anyone know how to accomplish this??
Comment
Watch Question

Commented:
try with

var slider = $("article.slider");
if (slider) {
        var right = (slider.css("right")).length - 2;
        var left = (slider.css("left")).length - 2;
}

Open in new window

Author

Commented:
nope that didn't make a difference.
Multitechnician
Distinguished Expert 2019
Commented:
you may use :

var slider = $("article.slider");
if (slider.length>0) {
        var right = ($(slider).css("right")).length - 2;
        var left = ($(slider).css("left")).length - 2;
}

Author

Commented:
thanks!! =)