jQuery Selectors

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

jQuery Selectors

Post by twinedev »

Ok, I'm just really getting starting jQuery (only framework I used before was mooTools, usually hand code all JS)

Anyhow, could use some help in the selectors, here is the basic structure of my code:

Code: Select all

	<ol class="sortable" id="sortRoot">
		<li id="list_227">
			<div class="line-cover" id="debug_228">
				<div id="debug_208" class="tools">
					<div id="debug_230" class="norm exp">Open/Close</div>
					<div id="debug_231" class="norm edit">Edit</div>

					<div id="debug_232" class="norm del">Delete</div>
					<div id="debug_233" class="norm add">Add</div>
					<div id="debug_234" class="editing save">Save</div>
					<div id="debug_235" class="editing cancel">Cancel</div>
				</div>
and I'm trying to get the Div that contains the "Open/Close". The following gets it ( $(this) is the li id="list_227" from an .each() ):

Code: Select all

var expDiv = $(this).children("div").children("div.tools").children("div.exp") ;
however, from what I understand about selectors (still learning), I thought the following would work:

Code: Select all

var expDiv = $(this).children("div > div.tools > div.exp") ;
However it doesn't, so obviously I'm thinking it wrong. Can someone explain if I'm just thinking wrong all together, or if I'm just stringing the elements together wrong.

Note, this is going through all the <li> items, so can't use the IDs.

I did learn quickly to add debug ID's to everything that doesn't have an ID set (the #'s are from PHP echoing out the line number). that has saved my sanity so much that I can just do a alert($(whatever).attr("id")); to test what it is actually using. They will all be gone on final program.

Thanks.

-Greg
Post Reply