Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7524651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:07:35+00:00 2026-05-30T03:07:35+00:00

im starting to use Backbone.js and im trying to do somthing simple with javascript,

  • 0

im starting to use Backbone.js and im trying to do somthing simple with javascript, which is show/hide divs. I get to show the div but i cannot hide it, i try many things, any idea? or could be it more sophisticated?

var Step1View = Backbone.View.extend({
    el: $('body'),
    events: {
        'click #more': 'more',
        'click #hide': 'hide',
    },

    initialize: function (){
        _.bindAll(this, 'render', 'more', 'next', 'less');
        this.render();
    },

    render: function (){
        var self = this;
        $(this.el).append("<a id='more'>Show more</a>");
        $(this.el).append("<div id='show' style='display: none'>Div12</div>");
        return this;
    },

    more: function (){
        $('#more').text('Hide more');
        $('#more').attr('id', '#hide');
        $('#show').show();
    },

    less: function (){
        $('#hide').text('Show more');
        $('#show').hide();
    },

});

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:07:36+00:00Added an answer on May 30, 2026 at 3:07 am

    You have a lot of problems here.

    You’re trying to bind an event to a non-existent hide method, your events should look like this:

    events: {
        'click #more': 'more',
        'click #hide': 'less',
    },
    

    Your initialize method is trying to bind a method, next, which does not exist. Your initialize should look more like this:

    initialize: function (){
        _.bindAll(this, 'render', 'more', 'less');
        this.render();
    },
    

    Your more method is setting the id to #hide but it should be hide:

    more: function (){
        $('#more').text('Hide more').attr('id', 'hide');
        $('#show').show();
    },
    

    Your less method doesn’t switch the id back to more:

    less: function (){
        $('#hide').text('Show more').attr('id', 'more');
        $('#show').hide();
    }
    

    And you have a stray comma after less which will make some browsers unhappy.

    Demo: http://jsfiddle.net/ambiguous/8HkdT/

    Swapping the id attributes like that is a bit dodgy. You’d be better off with separate links that you show and hide along with the <div> or just a single toggle button that does both the showing and hiding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting to use the jquery $.ajax() but I can't get back what
I am starting to use some Java code which was written by someone else.
I'm starting to use Moq and I cannot figure out how to test the
I'm starting to use LINQ, and I'm very happy with its intuitive use, but
I'm starting to use facebook graph api to create events with javascript! It works
Just starting to use Cruise Control, but can't seem to find anything on this
I'm just starting to use Moose . I'm creating a simple notification object and
I'm just starting to use Xcode 4, and I'm trying to find the file
Background: I'm starting to use Django for the first time, which is also my
I'm just starting to use YUI. I'm trying to understand how to subscribe elements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.