简体   繁体   中英

get specific element jquery in repetitive structure

As mentioned in the title i have the following structure of HTML file

<div class="field">
    <select class="cust_select"  id="E3_F0080_IdNatCertif" name="E3_F0080_IdNatCertif" sb="97342998" style="display: none;" >
        <option value="" selected="selected">[Sélectionnez une nature de certification]</option>
        <option value="9" selected="selected">Diplôme d'etat</option>
        <option value="1">Titre ou diplome enregistre au RNCP</option>
        <option value="8" selected="selected">CQP</option>
        <option value="14" selected="selected">Diplome d'universite</option>
        <option value="4">Attestation de fin de stage</option>
    </select>

    <div id="sbHolder_97342998" class="sbHolder">
        <a id="sbToggle_97342998" href="#" class="sbToggle"></a>
        <a id="sbSelector_97342998" href="#" class="sbSelector">Diplome d'etat</a>
        <ul id="sbOptions_97342998" class="sbOptions" style="top: 30px; max-height: 489.766px; display: none;">
            <li>
                <a href="#" rel="" class="">[Selectionnez une nature de certification]</a>
            </li>
            <li>
                <a href="#9" rel="9" class="">Diplome d'état</a>
            </li>
            <li>
                <a href="#1" rel="1" class="">Titre ou diplôme enregistré au RNCP</a>
            </li>
            <li>
                <a href="#8" rel="8" class="">CQP</a>
            </li>
            <li>
                <a href="#14" rel="14" class="">Diplôme d'université</a>
            </li>
            <li>
                <a href="#4" rel="4">Attestation de fin de stage</a>
            </li>
        </ul>
    </div>
</div>
<div class="error" id="E3_M3_0080_IdNatCertif"></div>

<div class="field">
    <select class="cust_select"  id="E4_F0080_IdNatCertif" name="E4_F0080_IdNatCertif" sb="97342998" style="display: none;" >
        <option value="" selected="selected">[Sélectionnez une nature de certification]</option>
        <option value="9" selected="selected">Diplôme d'etat</option>
        <option value="1">Titre ou diplome enregistre au RNCP</option>
        <option value="8" selected="selected">CQP</option>
        <option value="14" selected="selected">Diplome d'universite</option>
        <option value="4">Attestation de fin de stage</option>
    </select>

    <div id="sbHolder_666555" class="sbHolder">
        <a id="sbHolder_666555" href="#" class="sbToggle"></a>
        <a id="sbHolder_666555" href="#" class="sbSelector">Diplome d'etat</a>
        <ul id="sbHolder_666555" class="sbOptions" style="top: 30px; max-height: 489.766px; display: none;">
            <li>
                <a href="#" rel="" class="">[Selectionnez une nature de certification]</a>
            </li>
            <li>
                <a href="#9" rel="9" class="">Diplome d'état</a>
            </li>
            <li>
                <a href="#1" rel="1" class="">Titre ou diplôme enregistré au RNCP</a>
            </li>
            <li>
                <a href="#8" rel="8" class="">CQP</a>
            </li>
            <li>
                <a href="#14" rel="14" class="">Diplôme d'université</a>
            </li>
            <li>
                <a href="#4" rel="4">Attestation de fin de stage</a>
            </li>
        </ul>
    </div>
</div>
<div class="error" id="E4_M4_0080_IdNatCertif"></div>

As you can see below its about a div containing a select and another div.

All i want is to access the <a> element with the class sbSelector that is inside the div that comes after the select that has the id E3_F0080_IdNatCertif (which is the first in this example only)

ps: i cannot use ids of divs here because as you can see its generated via jquery code and it affects random uid each time he creates a select list (dropDownList) and i use jquery 1.5.1

It would be nice if anyone can provide me http://JSFiddle code samples. Thanks in advance

This fiddle will work. The core is here:

$("#E3_F0080_IdNatCertif + div a.sbSelector")

In the fiddle, you can enter and affect the element, like:

$("#E3_F0080_IdNatCertif + div a.sbSelector").text('Hello')

and will work as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM