[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

jQuery: Animate parent and cousin with one statement

Posted on 2013-05-29
3
Medium Priority
?
231 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 43

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses

656 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