2

I have some groups of content which consists of two divs, both divs contain text, and I want the second div of each set to match the height of the first.

DEMO

HTML (Cannot be changed unfortunately)

<!-- group one --> <div class="item"> .... content here </div> <div class="item_open"> .... content here too </div> <!-- group two --> <div class="item"> .... completely different content here </div> <div class="item_open"> .... some more content here too </div> 
2
  • Is the content dynamically changed after page load? Commented Mar 4, 2014 at 14:46
  • It's going to be responsive and any text in the second div will have overflow: scroll; on .... if I need to I will just run it on re-size. Commented Mar 4, 2014 at 14:48

5 Answers 5

6

Try this

$('.item_open').height(function(){ return $(this).prev().height(); }); 

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

That's perfect thanks! I knew it would be a fairly simple solution, it's just figuring out how to use it. I was originally thinking of going down the route of .closest(), but figured it was better I ask here first.
2

Fiddle Demo

$('.item_open').height(function(){ return $(this).prev().height(); }); 

.height()

.prev()

Comments

1

I'm pretty sure that what you are looking for could be found here: http://www.ejeliot.com/blog/61

(Using CSS and not JQuery)

1 Comment

I've used that method before and it's good but wouldn't work for what I'm doing. Thanks anyway!
1

Here is a fiddle using jQuery to achieve this.

http://jsfiddle.net/59Rhn/4/

$(".item_open").each(function(){ $(this).height($(this).prev().height()); }); 

Comments

0

If you cannot change HTML, you can try in this way..

var $item = $(document).find('.item'); // find first tag item var $itemNext = $item.next(); // return item_open $($item, $itemNext).css({ height: '100px' }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.