Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7741327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:59:53+00:00 2026-06-01T08:59:53+00:00

I have the following HTML markup: <select name=Fault class=textbox id=fault> <option>Single Light Out</option> <option>Light

  • 0

I have the following HTML markup:

<select name="Fault" class="textbox" id="fault">
<option>Single Light Out</option>
<option>Light Dim</option>
<option>Light On In Daytime</option>
<option>Erratic Operating Times</option>
<option>Flashing/Flickering</option>
<option>Causing Tv/Radio Interference</option>
<option>Obscured By Hedge/Tree Branches</option>
<option>Bracket Arm Needs Realigning</option>
<option>Shade/Cover Missing</option>
<option>Column In Poor Condition</option>
<option>Several Lights Out (please state how many)</option>
<option>Column Leaning</option>
<option>Door Missing/Wires Exposed</option>
<option>Column Knocked Down/Traffic Accident</option>
<option>Lantern Or Bracket Broken Off/Hanging On Wires</option>
<option>Shade/Cover Hanging Open</option>
</select>

<span id="faulttext" style="color:Red; display:none">Text in the span</span>


<select name="Fault" class="textbox" id="faultw">
<option>Single Light Out</option>
<option>Light Dim</option>
<option>Light On In Daytime</option>
<option>Erratic Operating Times</option>
<option>Flashing/Flickering</option>
<option>Causing Tv/Radio Interference</option>
<option>Obscured By Hedge/Tree Branches</option>
<option>Bracket Arm Needs Realigning</option>
<option>Shade/Cover Missing</option>
<option>Column In Poor Condition</option>
<option>Several Lights Out (please state how many)</option>
<option>Column Leaning</option>
<option>Door Missing/Wires Exposed</option>
<option>Column Knocked Down/Traffic Accident</option>
<option>Lantern Or Bracket Broken Off/Hanging On Wires</option>
<option>Shade/Cover Hanging Open</option>
</select>

<span id="faulttextw" style="color:Red; display:none">Text in the span</span>

and the following jquery script:-

$(document).ready(function(){

$('#fault option:nth-child(n+12)').wrapAll('<optgroup label="Urgent Faults">');

$('#faultw option:nth-child(n+12)').wrapAll('<optgroup label="Urgent Faults">');

$("#fault").change(function (event) {
    var $selected = $(this).find("option:selected");
    $("#faulttext").fadeToggle(!!$selected.closest("optgroup").length);
});

$("#faultw").change(function (event) {
    var $selected = $(this).find("option:selected");
    $("#faulttextw").fadeToggle(!!$selected.closest("optgroup").length);
});

});

Notice that there are two select lists and two spans, the second set is suffixed with a w.

Also notice that the above jquery is duplicated to deal with the suffixed set of elements.

How would i modify/tidy the above jquery to deal with both?

Using #fault, #faultw option:nth-child(n+12) as a selector doesn’t seem to work.

Also on the second bit of the jquery, if i am to handle the change event using $("#fault, #faultw").change then i would need to fadeToggle the matching span text.

Or is it best to keep it simple and leave it as it is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:59:55+00:00Added an answer on June 1, 2026 at 8:59 am

    The comma acts like an OR, thereby starting an unrelated selector – the option:nth-child(n+12) part at the end only applies to the rest of the selector after the comma, not the selector before it as well. You’ll need to use: #fault option:nth-child(n+12), #faultw option:nth-child(n+12).

    As for the change event handler, you could use a HTML5 data-* attribute on the <select> element to specify the ID of the span to work with.

    HTML:

    <select name="Fault" class="textbox" id="fault" data-spanid="faulttext">
        // options
    </select>
    
    <span id="faulttext" style="color:Red; display:none">Text in the span</span>
    
    
    <select name="Fault" class="textbox" id="faultw" data-spanid="faulttextw">
        // options
    </select>
    
    <span id="faulttextw" style="color:Red; display:none">Text in the span</span>
    

    jQuery:

    $("#fault, #faultw").change(function (event) {
        var $selected = $(this).find("option:selected");
        $("#" + $(this).data('spanid')).fadeToggle(!!$selected.closest("optgroup").length);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML markup:- <select name=List1 id=l1> <option>One</option> <option>Two</option> <option>Three</option> <option>Four</option> <option>Five</option>
I have the following html markup: <div class=wrap_select> <span class=select id=selectdateRange>Today, 25 March, Sun</span>
I have the following markup. @(Html.Telerik().Grid(Model) .Name(Grid) .DataKeys(keys => keys.Add(key => key.Id)) .Columns(columns =>
I have the following HTML markup: <body> <div class=wrapper> <div class=head> <p class=title>title</p> <a
I currently have the following HTML markup: <td class=title> <img src=my-image.png class=thumbnail /> <span
I have the following HTML markup : <a class=link1 href=javascript:load(0,1);>Click here</a><span class=loader></span> The load
I have the following HTML markup: <div class=votes meta engagement> <span class=vote-count> <span class=vote-total>
I have the following html markup on my page, <div id=sig_container> <div id=layer1 class=layer
I have the following HTML markup. <div class=caption> <img class='active' alt='My Caption' src='path/to/image' />
I have the following HTML markup: <div class=drag a></div> <div class=drop a></div> I also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.