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 8645165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:28:44+00:00 2026-06-12T12:28:44+00:00

i create a div dynamically and add this dynamic div into another div. i

  • 0

i create a div dynamically and add this dynamic div into another div. i was trying to animate div and i use to add/remove class and hasclass function to have some kind of toggle function. but my code do not work properly. have a look at this portion and tell me is there any problem.

if(oDiv.hasClass('test')) {
return oDiv.animate({ opacity: 'toggle', marginTop:('-' + allChildDivHeight + 'px')    },  speed, easing, callback);
$oDiv.removeClass('test');        
    }
    else
    {

 return oDiv.animate({ opacity: 'toggle', marginTop:('-' + (margin_top+allChildDivHeight )+ 'px') }, speed, easing, callback);
 oDiv.addClass('test');

    }

can i use jquery toggle function to have this kind of effect like

$('.btnName').click(function() {
$('#panel').toggle(function() {
$(this).animate({ 
 // style change
}, 500);
},
function() {
$(this).animate({ 
 // style change back
}, 500);
});

the above code is just a sample. i just need to know can i use something like to have toggle functionality.

i wrote it like below way using toggle but still not working

oDiv.toggle(function()
{
alert('class'+allChildDivHeight );
return oDiv.animate({ opacity: 'toggle', marginTop:('-' + allChildDivHeight + 'px') }, speed, easing, callback);

},function()
{
alert('no class'+(margin_top+allChildDivHeight));
return oDiv.animate({ opacity: 'toggle', marginTop:('-' + (margin_top+allChildDivHeight )+ 'px') }, speed, easing, callback);
});

please have look at my code at top most. the full code is here http://jsfiddle.net/tridip/PTdsz/8/

please go there to see my full code and tell me why always controls goes in to this if
if(oDiv.hasClass('test')) {}

why remove class is not working like $oDiv.removeClass('test');

please help. thanks

  • 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-06-12T12:28:47+00:00Added an answer on June 12, 2026 at 12:28 pm

    You are returning before you remove the class that’s why!

    Your $oDiv.removeClass('test'); is never called see:

            if(oDiv.hasClass('test')) {
            alert('class'+allChildDivHeight );
            return oDiv.animate({ opacity: 'toggle', marginTop:('-' + allChildDivHeight + 'px') }, speed, easing, callback);
            $oDiv.removeClass('test');        <------ This is never called
        }
    

    Because you have a return in the line before.

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

Sidebar

Related Questions

i am trying to bind an event to a dynamically created div. function GameField(playerNumber)
I am using this script with jquery for my dynamic add/remove input field: <script>
I am trying to create nested repeaters dynamically using ITemplate. This repeater is like
In some page, my side menu is created dynamically like this. <div id=tree class=treeview>
I am able to create div tag dynamically but unable to create form tag
I create Any div in auto width with single image background. in act this
I'm trying to create a new div each time a text field contained in
I am creating an li element dynamically like this: $(data).find('slide').each(function(numSlide){ var slideLink = $(this).attr('link');
I'm trying to create a list of so called portlets, dynamically. Portlets can be
I am trying to create a jquery UI nested tab dynamically on a button

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.