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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:10:25+00:00 2026-06-18T09:10:25+00:00

My CODE HTML: <p id="console"></p> <button>Click <span class="icon"></span> </button> JS: $(‘.icon’).click(function () { $(‘#console’).html(‘Icon

  • 0

My CODE


HTML:

<p id="console"></p>
<button>Click <span class="icon"></span>
</button>

JS:

$('.icon').click(function () {
    $('#console').html('Icon has been clicked');
    return false;
});

$('button').click(function () {
    $('#console').html('Button has been clicked');
});

CSS:

.icon {
    background-position: -96px 0;
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-top: 1px;
    line-height: 14px;
    vertical-align: text-top;
    background-image: url("http://twitter.github.com/bootstrap/assets/img/glyphicons-halflings.png"); 
    background-repeat: no-repeat;
}

Demo

Problem


I am able to click on .icon in Chrome , but not in Firefox. When I click on .icon, it clicks on whole button.

Question:


Isnt my code valid ? If my code is valid, whats the solution to this problem.

What I have tried


  1. I have tried doing $('.icon').click() from console and it works perfectly in ff, so I guess the problem is that span is not clickable inside button.

  2. e.preventDefault() and e.stopPropagation are not working either.

  3. I’ve tried putting &nbsp; inside span but its not working either.

  • 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-18T09:10:26+00:00Added an answer on June 18, 2026 at 9:10 am

    Refer to the spec, most notably the forbidden contents (in the SGML definition; for assistance reading that, look here): as, forms, form “controls” (input, select, etc), and fieldsets.

    While you are correct in asserting that spans (and divs, etc) are legal contents of a button element, the illegal elements are all to do with having button content that does anything other than layout / styling.

    I don’t see anything in the spec precluding what you’re trying to do, but I do see a lot discouraging it, and would be unsurprised if various browsers also “discouraged” that by not supporting it.

    Which is to say: find another way to do what you want if you want to have cross-browser support. I don’t understand what you’re actually trying to do, so I don’t think its possible to propose alternatives. I get that you want to respond differently to clicking on the button vs the icon — but that’s a (good, btw) demonstration of what you don’t want to happen, not an explanation of an actual problem you want to solve.

    One way might be to not use a button, and instead use another span or a div:

    <p id="console"></p>
    <div class="button_replace">Click <span class="icon"></span></div>
    <script>
      $('.icon').click(function () {
        $('#console').html('Icon has been clicked');
        return false;
      });
      $('.button_replace').click(function () {
        $('#console').html('Button has been clicked');
      });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code : HTML <div id="box"> <div class="mappa-infobox"> <div class="pulsanti"> <span class="pulsante selected">YES</span> <span
First my code: Html <div class="product_image m2" id="m2"><a href="#" id="10" class='multi2'>test..</a></div> JS $(document).ready(function(){ $("#m2
This is a simple code : HTML <a id="link" href="#">Ciao</a> jQuery $('#link').click(function () {
I have a button in my webpage with below code - HTML: <button type="submit"
This is my code : HTML <div style="float:left; width:100px;"> <a class="openTab" href="http://www.link.it">1 Line</a> <div
I have this code : HTML <div class="box_video"> <object width="330" height="290" type="application/x-shockwave-flash" data="http://www.youtube.com/v/KEkR1ox_K10?version=3&amp;f=user_uploads&amp;app=youtube_gdata&amp;rel=1&amp;border=0&amp;fs=1&amp;autoplay=0" style="visibility:
I have this code : HTML <div class="draggable_container"> <div id="draggable_1" class="draggable">&nbsp;</div> </div> CSS .draggable_container
This is my code : HTML <div id="fb-root"></div><script>window.fbAsyncInit = function() { FB.init({ appId: '1234',
I wrote a jquery code to send values to a php file $('#def_formSubmit').live("click",function(){ var
Check this code : HTML : <div style="position: absolute; visibility: visible; width: 172px;"> <img

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.