0

At this point time I'm assuming jQuery uses exactly the same format as CSS does when using CSS selectors.

However, I have the following line in my JS (with a log to try and find the problem)

boxheight = $('.item .active > .html-carousel-slide > .slide-content-box').height();
    console.log(boxheight);

Now when I view the console log it just says Null, I'm assuming that it did not select properly and thus the variable was never initialized in the first place so remained at Null.

Am I selecting the element wrong? Definitely the correct hierarchy.

6
  • Works fine for me: jsfiddle.net/v750dsL5 What is the HTML you are having trouble with? Commented Aug 3, 2016 at 1:30
  • @person66 I'm basically creating a function that changes the top property of a box to (slider it is in's height - (boxes height /2)) in order to have a constant vertical center of the box. Here is my HTML for the slide pastebin.com/7edC1hef Commented Aug 3, 2016 at 1:35
  • Post a minimal reproducible example in your question please Commented Aug 3, 2016 at 1:37
  • @FelipeWarrener Your selector syntax is wrong, you don't want a space between item and active, you want .item.active > .... If you use .item .active (with the space) then you are selecting .active that is a descendant of .item Commented Aug 3, 2016 at 1:37
  • .item .active should be .item.active (no space) since your div is both .item and .active Commented Aug 3, 2016 at 1:38

1 Answer 1

3

You have the element <div class="item active"> in your HTML and are trying to select it with .item .active which is incorrect. Use .item.active instead. The space between the classes says select all elements that have the class active that are descendants of all elements with the class item. What you really wanted to say was select the elements that have both the item and active classes, which you do by removing the space between the two.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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