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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:52:44+00:00 2026-06-18T00:52:44+00:00

Please help. I’m trying to get html to show up depending on the ID

  • 0

Please help. I’m trying to get html to show up depending on the ID of the li. I thought I knew what I was doing, but it always helps for someone else to look at it.

<div id="calcchooser">
<ul>
<h3>Black and White</h3>
    <li id="bwsoftcover" class="calcbutton s">Paperback</li>
    <li id="bwhardcover" class="calcbutton">Hardcover</li><br><br>
<h3>Standard Color</h3>
    <li id="standardpaperback" class="calcbutton">Paperback</li>
    <li id="standardhardcover" class="calcbutton">Hardcover</li><br><br>
<h3>Premium Color</h3>
    <li id="premiumpaperback" class="calcbutton">Paperback</li>
    <li id="premiumhardcover" class="calcbutton">Hardcover</li><br><br>
<h3>Ebook</h3>
<li id="ebook" class="calcbutton">Ebook</li><br><br>
<h3>Selected Product: <span id="selectedproduct">Black and White Paperback</span></h3>    

$("#calcchooser li").click(function () {

var bwsoftcover = "Black and White Softcover"
var bwhardcover = "Black and White Hardcover"
var standardsoftcover = "Standard Color Softcover"
var standardhardcover = "Standard Color Hardcover"
var premiumsoftcover = "Premium Color Softcover"
var premiumhardcover = "Premium Color Hardcover"
var ebook = "Ebook"

$("#percentchooser li").removeClass("s");
$(this).addClass("s");

if( $(this).is('#bwsoftcover'); )    
    {$("#selectedproduct").hide().html(bwsoftcover).fadeIn();}
if( $(this).is('#bwhardcover'); )    
    {$("#selectedproduct").hide().html(bwhardcover).fadeIn();}
if( $(this).is('#standardsoftcover'); )    
    {$("#selectedproduct").hide().html(standardsoftcover).fadeIn();}
if( $(this).is('#standardhardcover'); )    
    {$("#selectedproduct").hide().html(standardhardcover).fadeIn();}
if( $(this).is('#premiumsoftcover'); )    
    {$("#selectedproduct").hide().html(premiumsoftcover).fadeIn();}
if( $(this).is('#bwhardcover'); )    
    {$("#premiumhardcover").hide().html(premiumhardcover).fadeIn();}
if( $(this).is('#ebook'); )    
    {$("#selectedproduct").hide().html(ebook).fadeIn();}


});

CSS if desired

li {
display:inline-block;
list-style:none;
margin-right:5px;
position:relative;
cursor:pointer;
}

#calcchooser h3 {
font-weight:bold;
font-size:24px;
}

.calcbutton {
-moz-box-shadow:inset 0px 1px 0px 0px #bee2f9;
-webkit-box-shadow:inset 0px 1px 0px 0px #bee2f9;
box-shadow:inset 0px 1px 0px 0px #bee2f9;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #63b8ee), color-stop(1, #468ccf) );
background:-moz-linear-gradient( center top, #63b8ee 5%, #468ccf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#63b8ee', endColorstr='#468ccf');
background-color:#63b8ee;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #3866a3;
display:inline-block;
color:#14396a;
font-family:arial;
font-size:13px;
font-weight:bold;
padding:3px 7px;
text-decoration:none;
text-shadow:1px 1px 0px #7cacde;
}.calcbutton:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #468ccf), color-stop(1, #63b8ee) );
background:-moz-linear-gradient( center top, #468ccf 5%, #63b8ee 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#468ccf', endColorstr='#63b8ee');
background-color:#468ccf;
}.calcbutton:active {
position:relative;
top:1px;
 }

/* This imageless css button was generated by CSSButtonGenerator.com */

  • 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-18T00:52:45+00:00Added an answer on June 18, 2026 at 12:52 am

    I’d suggest:

    var opts = {
        bwsoftcover: 'black and white paperback',
        bwhardcover: 'black and white hardcover',
        standardpaperback: 'standard color softcover',
        standardhardcover: 'standard color hardcover',
        premiumpaperback: 'premium color softcover',
        premiumhardcover: 'premium color hardtcover',
        ebook: 'ebook'
    };
    
    $('#calcchooser li[id]').click(function () {
        $(this).addClass('s').siblings().removeClass('s');
        var text = opts[this.id];
        $('#selectedproduct').fadeOut(300, function () {
            $(this).text(text).fadeIn(300);
        });
    
    });
    

    JS Fiddle demo.

    The key to this answer is, really, using an object (similar in principle to an array, but with alphanumeric keys), with values stored with keys that are the same as the id of the li elements you want your users to click. Effectively each time an li (that has an id) is clicked it retrieves the value from the array with the key equal to that id with the following line:

    var text = opts[this.id];
    

    This also allows you to enter a default message in the event that a new id is added without a corresponding value in the object (due to a typo or oversight), for example:

    var text = opts[this.id] || 'Default message here';
    

    This relies on the returned value from the opts[this.id] being ‘falsey’, it would normally be undefined if there was no key equal to the id, so you could be more strict with a ternary operator:

    var text = opts[this.id] !== undefined ? opts[this.id] : 'Default message here';
    

    This approach also avoids the use of all the if assessments and the is() method (which makes it considerably cheaper to run).

    And, further, by using a JavaScript object to contain the descriptions against the relevent element id avoids redeclaring the same variables every time the click() method is used.

    Further, I’ve corrected the HTML to enclose the h3 elements within an li.

    References:

    • jQuery (at the jQuery API):
      • addClass().
      • fadeIn().
      • fadeOut().
      • removeClass().
      • siblings().
      • text().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me, I'm trying to find some documentation about pre-installed applications at Android.
Please help me get the substring of the following text. I would like to
Please help me to get efficient way to find Numeric String. String str =-100000.000;
Please help me I am new to Maven. I am trying to generate a
Please help me... i am trying to update my database from VB.net. It shows
Please help me. I know this is very simple, but my bad luck :(
Please help me someone with this code. CSS Code #nav, #nav ul { width:1000px;
Please help, I am trying to set up a rails app on Ubuntu 12.04,
Please help me i want to get position of imageview on a layout.
Please help me solve this file path conflict: As you know, many HTML pages

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.