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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:54:48+00:00 2026-05-16T00:54:48+00:00

Consider this snippet: <div> <span style=color:red;>a</span> <span style=color:blue;>a</span> <span style=color:white;>a</span> </div> How can you

  • 0

Consider this snippet:

<div>
     <span style="color:red;">a</span>
     <span style="color:blue;">a</span>
     <span style="color:white;">a</span>
</div>

How can you remove style from selected by user text?


Edited: to add clarifications from OP:

Thank you for your answers!
I had to be more precise. Sorry for that.
What do I mean by “selected by user text”: selected/highlighted with mouse.
I have many divs with spans inside(just like it is below-no extra ids,classes for spans:/).

[...]
<div>
 <span style="color:red;">a</span>
 <span style="color:blue;">b</span>
 <span style="color:white;">c</span>
</div>
<div>
 <span style="color:red;">d</span>
 <span style="color:blue;">a</span>
 <span style="color:white;">a</span>
</div>
[...]

What I would like to achieve: user selects with mouse “ab”, click button(input type=button) which remove style from selected span/spans. Similar behavior like it is in TinyMCE.

  • 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-05-16T00:54:48+00:00Added an answer on May 16, 2026 at 12:54 am

    I’m not sure what you mean by “selected by user text”, but if you mean that you want the user to be able to click on the text to remove its color, you could do it this way with jQuery:

    Try it out: http://jsfiddle.net/v24fZ/

    $(function() {
        $('div > span').click(function() {
            $(this).removeAttr('style');
        });
    });
    

    Note that this will affect all <span> elements that are a child of a <div>, so better would be to place an ID attribute on the <div> to make sure you have the right one.

    Try it out: http://jsfiddle.net/v24fZ/1/

    <div id="myID"><span style="color:red;">a</span><span style="color:blue;">a</span><span style="color:white;">a</span></div>
    

    then

    $(function() {
        $('#myID > span').click(function() {
            $(this).removeAttr('style');
        });
    });
    

    Also note that this will remove all inline styles. If you only want to remove the color, then do this:

    Try it out: http://jsfiddle.net/v24fZ/2/

    $(function() {
        $('#myID > span').click(function() {
            $(this).css('color', '');
        });
    });
    
    • http://api.jquery.com/removeAttr/
    • http://api.jquery.com/css/
    • http://api.jquery.com/click/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this snippet, obtained from an export: <!--l. 266--><p class=indent > <span class=ptmr8t-x-x-90></span><span class=ptmri8t-x-x-90>Blah
Please consider this HTML and CSS snippet: #container { border: 1px solid red; height:
Please consider this code snippet: var ul = $(.list_b).find(li).remove().end(); $.each(Sites, function (index, value) {
Consider this code snippet that prompts the user to rate the app on the
Relevant snippet from test.html: <div id="seat_31F_vacant" class="seatVacant" onclick="UpdateHost(this);Common.DoPostBack('lbtPostBack','31F');" onmouseover="Seat_onMouseOver(this)" onmouseout="Seat_onMouseOut(this)">F</div> Now consider this ruby
Consider the following snippet of code: <div align=Left> <font style='font-size:17pt; font-family:Times New Roman;color:#000000;'> <textformat
Consider this snippet: globalVar = 25 def myfunc(paramVar): localVar = 30 print Vars: {globalVar},
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
Consider this Python snippet: for a in range(10): if a == 7: pass if
Consider the following snippet: $(document).bind('mousemove', function(e) { $('#someDiv').css({left: e.pageX+'px', top: e.pageY+'px'}); }); This should

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.