?
Solved

jQuery: Animate parent and cousin with one statement

Posted on 2013-05-29
3
Medium Priority
?
230 Views
Last Modified: 2013-05-29
Using jQuery, how can I combine these two animate statements into a single animate statement?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

 $('.info-pops .show-info-pop').click(function () {

  $(this).parent().parent().find('.info-pop').animate({
                height: '+=50'
            }, 333, function () {
                // Animation complete.
  });
  $(this).parent().parent().parent().animate({
                height: '+=50'
            }, 333, function () {
                // Animation complete.
  });

 });

});

</script>
<style type="text/css">

.info-pops {
width: 100px;
height: 200px;
margin: 50 auto;
border: 5px solid black;
position: relative;
}

.info-pop {
width: 20px;
height: 100px;
margin: 50 auto;
border: 5px solid red;
position: absolute;
left: 20px;
}

.show-info-pop {
position: absolute;
right: 0;
cursor: pointer;
text-decoration: underline;
}

</style>

</head>
<body>

<div class="info-pops">
 <div>
  <div class="info-pop"></div>
  <p>
   <a class="show-info-pop">Grow</div>
  </p>
 </div>
</div>

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 42

Assisted Solution

by:David S.
David S. earned 200 total points
ID: 39204155
Try this:
$(document).ready(function() {

 $('.info-pops .show-info-pop').click(function () {
  var par = $(this).parents('.info-pops');
  par.add('.info-pop',par).animate({
                height: '+=50'
            }, 333, function () {
                // Animation complete.
  });

 });

});

Open in new window

0
 
LVL 38

Assisted Solution

by:Tom Beck
Tom Beck earned 200 total points
ID: 39204204
You could just go to the parent of all and find the descendants you want to animate:

$(document).ready(function() {
   $('.info-pops .show-info-pop').click(function () {
       $('body').find('.info-pop, .info-pops').animate({
                height: '+=50'
            }, 333, function () {
                // Animation complete.
        });
    });
});
0
 
LVL 10

Accepted Solution

by:
Ishaan Rawat earned 1600 total points
ID: 39204219
Try this.,,,...


$(document).ready(function() {

 $('.info-pops .show-info-pop').click(function () {

  ($(this).parent().parent().find('.info-pop'), $(this).parent().parent().parent()).animate({
                height: '+=50'
            }, 333, function () {
                // Animation complete.
  });
  

 });

});

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question