Jump to content

jquery - loop through all children of .each


RIRedinPA

Recommended Posts

If you have this html

 



<div id="tablebox">
	<ul>
		<li>
			<p>Field 1</p>
			<p>Field 2</p>
			<p>Field 3</p>
			<p>Field 4</p>
			<p>Field 5</p>
			<p>Field 6</p>
			<p>Field 7</p>
			<p>Field 8</p>
			<p>Field 9</p>
			<p>Field 10</p>
		</li>
	<ul>

	<ul>
		<li class="tablerow">
			<p>Field 1</p>
			<p>Field 2</p>
			<p>Field 3</p>
			<p>Field 4</p>
			<p>This is a lot of text that should throw the layout off</p>
			<p>Field 6</p>
			<p>Field 7</p>
			<p>Field 8</p>
			<p>Field 9</p>
			<p>This is a shorter amount of text</p>
		</li>
	</ul>
</div>

 

how would  I go about with jquery looping through each child of each <li> which met the argument class=tablerow?

 

i can get here but then stumble going through the children:

 


function init() { 
$(document).ready(function(){

   $('.tablerow').each(function(index) {
    	      var maxheight = 0;
              var childcount = $(this).children.length;
                 //this gives me the proper number of children, I now need to access the height of each one
    	      });
});
}

		window.onload = init;

Link to comment
Share on other sites

I got it working to an extent:

 

This will loop through all the child elements (<p>), (kind of obvious once I thought it through) but when I try to return the height I get a funky message...

 


<script language="javascript">

		function init() { 
			$(document).ready(function(){

				$('.tablerow').each(function(index) {
    					var maxheight = 0;
    					$(this).children().each (function() { 
    						alert($(this).height);
    					})
    				});
			});
		}

		window.onload = init;

	</script>

 

and the funky message is:

 

function (f) {
    var e = this[0];
    if (!e) {
        return f == null ? null : this;
    }
    if (c.isFunction(f)) {
        return this.each(function (j) {var i = c(this);i[d](f.call(this, j, i[d]()));});
    }
    return "scrollTo" in e && e.document ? e.document.compatMode === "CSS1Compat" &&
        e.document.documentElement["client" + b] ||
        e.document.body["client" + b] : e.nodeType === 9 ? Math.max(e.documentElement["client" + b], e.body["scroll" + b], e.documentElement["scroll" + b], e.body["offset" + b], e.documentElement["offset" + b]) : f === w ? c.css(e, d) : this.css(d, typeof f === "string" ? f : f + "px");
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.