Link to home
Create AccountLog in
Avatar of hindersaliva
hindersalivaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Wiring up a JavaScript function - jQuery

Hi, I need to fire off a JavaScript function when an image is clicked. At the moment I have this On Page Load.

    <script>
      (function($){
        $(window).load(function(){
          $(".content, .courselistscroll").mCustomScrollbar();
        });
      })(jQuery);
      </script>

Which works fine.

I have an image, when clicked it adds a class to a Div tag. But nothing happens (it should add scroll bar) ... that's because the function above has to be 're-fired', right?

So, how can I wire-up the above function to this I have already, please?
onclick="showscrollbars('lessons')

Thanks (I'm a JavaScript newbie ...)
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
$(function() {
});

Is equivalent to $(document).ready

Without seeing all your code this is a shot at it
$(function() {
  $('img').click(function() {
       $('#idofdiv').css({overflow: 'auto'});
  });
});

Open in new window

Avatar of hindersaliva

ASKER

Hmmm .... quick question to understand it before I try it ...

How would that fire-off the mCustomScrollBar() ?

Or, are we saying that that function will ADD the new class AND made the Div have the scroll bar?
I'm still not certain what your code is attempting to do. I based my answer on your comment:

I have an image, when clicked it adds a class to a Div tag. But nothing happens (it should add scroll bar)

Does the function mCustomScrollbar add the class or does it add the scrollbars?
Hi Kaufmed,
I have used this fantastic ScrollBar from here
http://manos.malihu.gr/jquery-custom-content-scroller/

I have configured it to work on the <Div id="content">. Tested. It works.

But I want the Div to load without the scroll bar on page load. That works also. I did that by not having the class="content" in that Div.

I have an image "Show Scroll Bars" and when the user clicks it I want the scroll bars to appear (without a page load, of course).

So, I thought the way to do it is to Add Class. (did a small test on a non-scroll bar demo and it works)
But when I put it in the page with the scroll bars it doesn't add the scroll bar. I thought, yes it's because the mCustomScrollbar is set to fire off on page load.

Maybe I'm needlessly going about it the long way?
Thanks for any help ...
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
You first say '<div id="content">', then you say 'class="content"'. Is "content" a class or an ID?
Sorry to confuse you!
"content" is a class. The ID = "lesson"

I shall try your solution Julian.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I had it working ... and then I screwed it up again! Anyway, there's a great deal I have learned.

(1) need to learn basic JS :(
(2) need to break my functionality down to small parts.

Thanks for your help, experts!