Noskiw Posted November 7, 2010 Share Posted November 7, 2010 I'm confused on how to do this... Is there any way to do this so that I could incorperate it into my code? Quote Link to comment https://forums.phpfreaks.com/topic/218026-how-to-select-the-child-of-the-selected-element-only-in-jquery/ Share on other sites More sharing options...
Adam Posted November 7, 2010 Share Posted November 7, 2010 Have you read up on .children()? Quote Link to comment https://forums.phpfreaks.com/topic/218026-how-to-select-the-child-of-the-selected-element-only-in-jquery/#findComment-1131437 Share on other sites More sharing options...
Noskiw Posted November 7, 2010 Author Share Posted November 7, 2010 I actually have and it doesn't help :/ Quote Link to comment https://forums.phpfreaks.com/topic/218026-how-to-select-the-child-of-the-selected-element-only-in-jquery/#findComment-1131440 Share on other sites More sharing options...
Adam Posted November 7, 2010 Share Posted November 7, 2010 Okay. What do you mean by selected element? If you can explain the problem in a little more detail, should be able to help you. Quote Link to comment https://forums.phpfreaks.com/topic/218026-how-to-select-the-child-of-the-selected-element-only-in-jquery/#findComment-1131451 Share on other sites More sharing options...
Noskiw Posted November 7, 2010 Author Share Posted November 7, 2010 Basically I have a <dt> element inside a <dl> element, and a <dd> element inside the <dl>. Now I want to make it when the <dd> element is showing, make the <a>* element yellow, but only the <dd< element that is showing, there are several * - The <a> element is inside the <dt> element Quote Link to comment https://forums.phpfreaks.com/topic/218026-how-to-select-the-child-of-the-selected-element-only-in-jquery/#findComment-1131453 Share on other sites More sharing options...
Noskiw Posted November 7, 2010 Author Share Posted November 7, 2010 For any of uoi who don't understand, here is the code: <!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>INSERT TITLE HERE!</title> <meta http-equiv="Content-type" content="text/html; charsetUFT-8" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta http-equiv="imagetoolbar" content="no" /> <link href="./css/core.css" rel="stylesheet" type="text/css" /> <script src="./js/jquery.js" type="text/javascript"></script> <script src="./js/functions.js" type="text/javascript"></script> </head> <body> <h1 style="padding: 20px;">INSERT NAME HERE!</h1> <div id="wr"> <dl id="acc"> <dt id="2"><a href="#">Home</a></dt> <dd id="1"><?php include "./inc/homes.php"; ?></dd> <dt><a href="#">Hi!</a></dt> <dd> <?php include "./inc/about.php"; ?> </dd> <dt><a href="#">Hi!</a></dt> <dd><?php include "./inc/mems.php"; ?></dd> <dt><a href="#">Hi!</a></dt> <dd><?php include "./inc/founded.php"; ?></dd> <dt><a href="#">Hi!</a></dt> <dd><?php include "./inc/contact.php"; ?></dd> </dl> </div> </body> </html> $(document).ready(function(){ if($("#acc").length > 0){ $("dd#1").slideToggle(200); $("dt#2").addClass("act"); $("#acc dt").click(function(){ var sel = $(this); sel.addClass("act current"); if($("dl").children("dd").is(":visible")){ if($("#acc dt").hasClass("current")){ $("#acc dt").children("a").addClass("asd"); } } sel.parent().children("dd").each(function(){ if($(this).is(":visible") && !$(this).prev("dt").hasClass("current")){ if($(this).prev("dt").hasClass("act")){ $(this).prev("dt").removeClass("act"); } $(this).slideUp(200); } }); sel.next().slideToggle(200, function(){ if(!$(this).is(":visible")){ $(this).prev("dd").removeClass("act"); } sel.removeClass("current"); if(!$(this).is(":visible")){ if($(this).click){ sel.removeClass("act"); } } }); return false; }); } }); This is the bit I'm struggling with if($("dl").children("dd").is(":visible")){ if($("#acc dt").hasClass("current")){ $("#acc dt").children("a").addClass("asd"); } } Quote Link to comment https://forums.phpfreaks.com/topic/218026-how-to-select-the-child-of-the-selected-element-only-in-jquery/#findComment-1131522 Share on other sites More sharing options...
Noskiw Posted November 8, 2010 Author Share Posted November 8, 2010 Help please? It's making them all yellow instead of the one I clicked Quote Link to comment https://forums.phpfreaks.com/topic/218026-how-to-select-the-child-of-the-selected-element-only-in-jquery/#findComment-1131843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.