# JavaScript function not firing off for owlcarousel-rails plugin

**URL:** <https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050>\
**Category:** rubyonrails-talk\
**Created:** [December 24, 2014, 6:06pm UTC](https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050 "2014-12-24T18:06:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [December 24, 2014, 6:06pm UTC](https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050/1 "2014-12-24T18:06:20Z")

</div>

The javascript is not working for 'owlcarousel-rails' plugin. I have the gem and require statements for application.css/application.js setup properly.

//= require owl.carousel \*= require owl.carousel \*= require owl.theme

I called the plugin with:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<script type= 'text/javascript' \> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(".owl-carousel").owlCarousel(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</script\> in my \<header\>\</header\>

\<div class="owl-carousel" style="z-index: 1;"\> \<div\>\<%= image\_tag 'JohnsPhotos/weekend-getaway1.jpg' %\>\</div\> \<div\>\<%= image\_tag 'JohnsPhotos/weekend-getaway2.jpg' %\>\</div\> \</div\> the tags for the plugin are mid page in the \<body\>\</body\>

Why isn't the javascript/css displaying the photos?

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [December 24, 2014, 7:26pm UTC](https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050/2 "2014-12-24T19:26:30Z")

</div>

> The javascript is not working for 'owlcarousel-rails' plugin.

Disclaimer: never heard of this plugin, but ---

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(".owl-carousel").owlCarousel();

if you're calling that method \*before\* any such elements exist in the DOM, I'd expect exactly nothing to happen 🙂

Have you looked at the JS console/log to see if there are errors?

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [December 24, 2014, 8:08pm UTC](https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050/3 "2014-12-24T20:08:34Z")

</div>

Hassan Schroeder wrote in post #1165339:

> > The javascript is not working for 'owlcarousel-rails' plugin.
> 
> Disclaimer: never heard of this plugin, but ---
> 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(".owl-carousel").owlCarousel();
> 
> if you're calling that method \*before\* any such elements exist in the DOM, I'd expect exactly nothing to happen 🙂
> 
> Have you looked at the JS console/log to see if there are errors?
> 
> -- Hassan Schroeder ------------------------ hassan.schroeder@gmail.com [Hassan Schroeder | about.me](http://about.me/hassanschroeder) twitter: @hassan

I'll try to call it after div code block, and then see if the function fires off. \<div class="row"\> &nbsp;&nbsp;&nbsp;&nbsp;\<div class="large-12 medium-12 small-2 columns mid-index-bg"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<h2 style="color: red; text-align: center;"\>Carousel Placeholder\</h2\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<div class="owl-carousel" style="z-index: 1;"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<div class="item"\>\<%= image\_tag 'Photo1'%\</div\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<div class="item"\>\<%= image\_tag 'Photo2'%\>\</div\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</div\> &nbsp;&nbsp;&nbsp;&nbsp;\</div\> &nbsp;&nbsp;\</div\>

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [December 24, 2014, 9:08pm UTC](https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050/4 "2014-12-24T21:08:11Z")

</div>

Hassan Schroeder wrote in post #1165339:

---

<div class="post-metadata">

**Author:** ![Colin\_Law](https://avatars.discourse-cdn.com/v4/letter/c/b9e5f3/32.png) [@Colin\_Law](https://discuss.rubyonrails.org/u/Colin_Law)\
**Post date:** [December 24, 2014, 10:04pm UTC](https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050/5 "2014-12-24T22:04:58Z")

</div>

View the source of the page in the browser to get a clue as to what is going on.

Colin

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [December 25, 2014, 3:55am UTC](https://discuss.rubyonrails.org/t/javascript-function-not-firing-off-for-owlcarousel-rails-plugin/70050/6 "2014-12-25T03:55:36Z")

</div>

I was calling an ID instead of a class with the initializer. Now, it's working perfectly!! Thank you all for taking the time out to guide me.
