A
A
Andrew2019-06-06 21:47:45
JavaScript
Andrew, 2019-06-06 21:47:45

Why does the script not find the element by id in Joomla?

There is a script and it works, but in joomla for some reason it does not find the element by id. Elements are defined by classes and tags. This line console.log(document.getElementById('arrowRight')); outputs null.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cyril, 2019-06-06
@wug1

document.addEventListener('DOMContentLoaded', function() {
    var Left = document.getElementById('arrowLeft'),
    Right = document.getElementById('arrowRight'),
    sliderLine = document.getElementById('sliderLine'),
    sliderItem = document.getElementsByClassName('sliderItem')[0],
    left = 0;

    function arrowLeft(){
        console.log(sliderItem);
        widthSliderItem = sliderItem.offsetWidth;
        left = left - widthSliderItem;
        if(left >= -2*widthSliderItem){
            sliderLine.style.left =  left + 'px';
        }else{
            sliderLine.style.left = 0 + 'px';
            left = 0;
        }
    }
    function arrowRight(){
        left = left + 950;
        if(left <= 0){        
            sliderLine.style.left = left + 'px';
        }else{
            left = 0;
        }
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question