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 9175581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:56:21+00:00 2026-06-17T16:56:21+00:00

I have one div with 4 spans in it: <div id=text> <span class=text_1 id=text1>text1

  • 0

I have one div with 4 spans in it:

<div id="text">
<span class="text_1" id="text1">text1 1</span>
<span class="text_2" id="text2">text2 2</span>
<span class="text_3" id="text3">text3 3</span>
<span class="text_4" id="text4">text4 4</span>
</div>

I have two buttons, buton1 that allows the class underline

.underline
 { border-bottom:1px solid #000; }

to be added to each span when i click each span (so if I click text1, then the other texts shouldn’t have an underline), and another button2 that should take off the underline until button1 is clicked again.

What I have is:

$('#button1').click(function () {

    $(".text_1").click(function () {
     $(".text_2").removeClass("underline");
     $(".text_3").removeClass("underline");
     $(".text_4").removeClass("underline");
     $('.text_1').addClass("underline");
});

     $(".text_2").click(function () {

     $(".text_1").removeClass("underline");
     $(".text_3").removeClass("underline");
     $(".text_4").removeClass("underline");
     $('.text_2').addClass("underline");
});
$(".text_3").click(function () {

     $(".text_2").removeClass("underline");
     $(".text_1").removeClass("underline");
     $(".text_4").removeClass("underline");
     $('.text_3').addClass("underline");
});

     $(".text_4").click(function () {

     $(".text_2").removeClass("underline");
     $(".text_1").removeClass("underline");
     $(".text_3").removeClass("underline");
     $('.text_4').addClass("underline");
}); 
});

meaning all of the above would happen iff button1 is clicked.

so button2, I want it to remove all underline from everything, but I don’t want to have to do all of the above over again because eventually I’m going to have like 100 span tags!

What I thought was correct would be something like

$('#button2').click(function () {

        $('#text').removeClass("underline") });   });

but that doesn’t work. (#text being the div id)

I then tried

$('#button2').click(function () {
     $(".text_2").removeClass("underline");
     $(".text_1").removeClass("underline");
     $(".text_3").removeClass("underline");
     $('.text_4').removeClass("underline");

I want it so that after you click button2, I cannot make the span text underline until I click button1. So the one directly above removes the underline class, but I can still click each span element and make it underline which I don’t want!

Could someone help me with this? I’m sort of new at this, so It’d be great if you could help me clean up button1’s functions too!!
Thank you!

  • 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-17T16:56:22+00:00Added an answer on June 17, 2026 at 4:56 pm

    You were almost there. Try the DEMO HERE

    var allowClick = true;
    
    $('#text span').click(function () {
      if (allowClick == true) {
        $('#text span').removeClass("underline");
        $(this).addClass("underline");
      }
    });
    
    $('#button1').click(function () {
      allowClick = true;
    });
    
    $('#button2').click(function () {
      $('#text span').removeClass("underline");
      allowClick = false;
    });
    

    Update:

    There is another solution also in which you can unbind the click event on span. But using a variable will be simple and faster. Consider unbinding if you can not create a global variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following markup; <div class=model-timeline> <p>Text</p> <div class=timeline> <div class=span-blank-5></div> <div class=time-span-1></div>
I have the following HTML structure: <div class=list-comments one> <ul> <li> <span>1</span> <p class=title><a
I have this div tags : <div id=target-share> <a href=# title= id=to-chosen class=default><span class=to-admin>Admin</span></a>
I have a template like script type: text/template, id: list-template, ''' <div class=display> <div
I have one large div with one smaller div inside it. The smaller div
I have one horizontally div on the top of my page with a height
I have one parent DIV inside parent DIV i have two DIV one in
I have two divs one inside another, i would like to overlap one div
I have one link in a div id where i have to disable the
I have created one menu using div animating in the middle i have structured.

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.