Getting Cannot read property 'offsetWidth' of undefined with bootstrap carousel script

JavascriptJqueryTwitter Bootstrap

Javascript Problem Overview


I created a carousel with Bootstrap 3.3 and it works on my local machine, but when I upload the whole thing on server where the bootstrap js file is being compiled together with other files in a single file, I get this error:

Cannot read property 'offsetWidth' of undefined - has anybody faced this and are there any known solutions to this issue?

Javascript Solutions


Solution 1 - Javascript

For me it was because I hadn't set an active class on any of the slides.

Solution 2 - Javascript

For me, I changed class='carousel-item' to class='item' like this

<div class="item">
    <img class="img-responsive" src="..." alt="...">
</div>

Solution 3 - Javascript

Remove the class 'Carousal slide' on page load & add it dynamically when image gets loaded using jquery.This fixed for me

Solution 4 - Javascript

I got same error. Because i used v4 alpha class names like carousel-control-next When i changed with v3, problem solved.

Solution 5 - Javascript

I have got the same error, but in my case I wrote class names for carousel item as .carousel-item the bootstrap.css is referring .item. SO ERROR solved. carosel-item is renamed to item

<div class="carousel-item active"></div>

RENAMED To the following:

<div class="item active"></div>

Solution 6 - Javascript

"Change to if (typeof $next == 'object' && $next.length) $next[0].offsetWidth" -did not help. if you convert Bootstrap 3 to php(for WordPress theme), when adding WP_Query ($loop = new WP_Query( $args );) insert $count = 0;. And and at the end before endwhile; add $count++;.

Solution 7 - Javascript

if you're using the compiled bootstrap, one of the ways of fixing it is by editing the bootstrap.min.js before the line

$next[0].offsetWidth 

force reflow Change to

if (typeof $next == 'object' && $next.length) $next[0].offsetWidth // force reflow

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionXeenView Question on Stackoverflow
Solution 1 - JavascriptJack JamesView Answer on Stackoverflow
Solution 2 - JavascriptsunnyView Answer on Stackoverflow
Solution 3 - JavascriptAnup ShettyView Answer on Stackoverflow
Solution 4 - JavascriptdgncnView Answer on Stackoverflow
Solution 5 - JavascriptHina AzharView Answer on Stackoverflow
Solution 6 - JavascriptSerhii HavryliukView Answer on Stackoverflow
Solution 7 - JavascriptBuchiView Answer on Stackoverflow