Going crazy looking for child of parent
I've searched the doc and this forum but cannot find anything that I can get to work - going slowly insane now...
Here is the code (note that this is really cut down for testing purposes):
-
<div id="sousrubrique10">
<div class="cssFormulaireBas">
<h3>
<a href="#sousrubrique10" class="folder">Fait générateur</a>
</h3>
</div>
<div class="contenu_sousrubrique"><!-- Document -->
<div class="deux_cases label_1_champs_1"> <label for="doc">Document</label> <input name="doc" id="doc" class="readonly" readonly="readonly" value="Mutation àTitre Onéreux" type="text" /> </div>
<div class="deux_cases label_1_champs_1"> <label for="datemutation">Date de la mutation</label> <input name="datemutation" id="datemutation" class="readonly" readonly="readonly" value="23/06/2008" type="text" /></div>
</div>
</div>
I have a style called "redborder" which is "border: 1px solid red".
When I click on the link I want to have the div with the class "contenu_sousrubrique" get the redborder class applied to it. I'm trying to do this by working up to the top div and then down to the child div, and I don't actually want to have to hard-code the id because in my live form I will have lots of these div's.
So here are my attempts:
1) This works, and adds the red border to div id="sousrubrique10" (but this is not what I want):
-
$(document).ready(function(){
$(".folder").click(function () {
var myparent = $(this).parent().parent();
$(myparent).addClass("redborder");
});
});
2) This works, and adds the red border to div class contenu_sousrubrique (I want to do this, but not using the hard-coded id):
-
$(document).ready(function(){
$(".folder").click(function () {
var myparent = $(this).parent().parent();
var thechild = $("#sousrubrique10").find(".contenu_sousrubrique");
$(thechild).addClass("redborder");
});
});
3) But this does not work (it actually has no apparent effect at all), and this is what I want to do...
-
$(document).ready(function(){
$(".folder").click(function () {
var myparent = $(this).parent().parent();
var thechild = $(myparent).find(".contenu_sousrubrique");
$(thechild).addClass("redborder");
});
});
I'm at my wits end about this, also I cannot find anything in the documentation that tells me how to combine variables and strings as selectors. I have also tried using ":last-child" but it highlights the h3 and the a, but not the div I want!!
Help much appreciated.[/code][/code]