1

I am working on an application and have the following jquery code in included .js file

function b(){}
b.prototype.expand=function(w){
    w.preventDefault();
    $(".sidebar-container").removeClass("sidebar-collapsed");
    $(".sidebar-collapse").show();
    $(".sidebar h2").show();
    $(".sidebar ul").show();
    $(".sidebar-expand").hide()
};
b.prototype.collapse=function(w){
    w.preventDefault();
    $(".sidebar-container").addClass("sidebar-collapsed");
    $(".sidebar-expand").show();$(".sidebar h2").hide();
    $(".sidebar ul").hide();
    $(".sidebar-collapse").hide()
};
b.prototype.listen=function(){
    $(document).on("click",".sidebar-collapse",this.collapse);
    $(document).on("click",".sidebar-expand",this.expand)
};

By Default the side panel is in expand condition and this code works fine for clicks but I have spent over 2 hours to make it to collapse by its By Default condition but no luck!

I am new to javascript and followed different methods by searching google and stackoverflow but no luck! Any help would be much appreciated, Thanks in advance.

3
  • run the collapse code on $(document).ready();? Hard to say unless you post collapse and expand methods... Commented Jan 20, 2016 at 15:59
  • Thanks for your kind reply, I just edited the post and placed some further code, can you please help now? I tried $(document).ready(this.collapse); But Not working. Commented Jan 20, 2016 at 16:04
  • How much control do you have over html and css? Why not apply the proper classes and styling to have it hidden when it loads instead of making it dependent on calling a function on document.ready? Commented Jan 20, 2016 at 16:07

1 Answer 1

1

You still hadn't posted your HTML code, so judging from what you have here, I'd do the following:

$(document).ready(function() {
    $(".sidebar-container").addClass("sidebar-collapsed");
    $(".sidebar-expand").show();
    $(".sidebar h2").hide();
    $(".sidebar ul").hide();
    $(".sidebar-collapse").hide()
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You Very Much! It is working and it really helps, As I told before, I am not smart at javascript, and all I was doing, were trying to place collapse function there. Your answer is 100% working as expected. :) Thumbs Up!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.