Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript JQuery index(); of parent-DIV

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #145527
    Leonhard Ortner
    Participant

    Hello People,

    i have tried to figure out how to get the index() value of a specific div…

    Basic HTML:

    <div class="rsContainer">
        <div class="rsSlide rsActiveSlide">
            <div class="rsContent" data-name="/A"></div>
        </div>
        <div class="rsSlide">
            <div class="rsContent" data-name="/B"></div>
        </div>
        <div class="rsSlide">
            <div class="rsContent" data-name="/C"></div>
        </div>
        <div class="rsSlide">
            <div class="rsContent" data-name="/D"></div>
        </div>
        <div class="rsSlide">
            <div class="rsContent" data-name="/E"></div>
        </div>
        <div class="rsSlide">
            <div class="rsContent" data-name="/F"></div>
        </div>
    </div>
    

    so here the code i have tried:

    var pathname = "/B";
    // this is a random one of the data-name values
    
    var currentslide = $(".rsActiveSlide").find(".rsContent").data("name");
    // this is active
    
    var rightone = $(".rsContainer").find(".rsContent" + "[data-name='" + pathname +"']");
    // this should be the active
    // here is the problem, all i need is the index(); of the parent.DIV (.rsSlide)
    
    if (currentslide != pathname) {
        goTo(index-of-rightone's-parent);
    }
    // so i could do: goTo(index); and the Slider will set the Slide which contains the "rightone" to be active
    

    Could someone help me? Thx you very much! Any Help is appreciatet…

    CodePen

    wbr Leo

    #145575
    Leonhard Ortner
    Participant

    Hello Guys,

    got this working:

    // SLIDE TO RIGHT SLIDE
        // setTimeout for Slider to get rdy
        setTimeout(function() {
    
            // pathname = url
            var pathname = window.location.href;
    
            // current active slide
            var currentslide = $(".rsActiveSlide").find(".rsContent").data("slide-infourl");
    
            if (pathname != currentslide) {
    
            // Select the right Slide width the corresponding URL in DATA-INFOURL
            var rightone = $(".rsContainer").find(".rsContent" + "[data-slide-infourl='" + pathname +"']").parent().index();
    
            // slider goTo
            slider.goTo(rightone);
    
            }
    
        }, 500);
    

    wbr leo

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.