Search code examples
jqueryjquery-animateparentchildren

jQuery parent and child animate


My code is like this and it's not working as expected.

function urSizeUp() {
 $('#someDiv', '#someDiv > div').animate({
  'width': '400px',
  'height': '100px'
 }, 500);
}

$('#someDiv').hover(urSizeUp);

The thing is to animate width and height for both parent and child elements. Is it possible to do at once, or do i have to write another function?

Edit

Here's a fiddle.

Notice that if you remove the second (or first) selector from both of the functions it works.


Solution

  • There's a few too many quotes in the selector :

    function urSizeUp() {
    
    $('#someDiv, #someDiv > div').animate({'width': 400, 'height': 100}, 500);
    }
    
    $('#someDiv').hover(urSizeUp);
    

    http://codepen.io/anon/pen/xboWoZ

    Edit - didn't see the fiddle at first...

    https://jsfiddle.net/50e1ohgk/1/