Set a span visible and invisble

32,756

I am not sure what Config.ISCavailability does, but what you should not use the visible property. The end result you want is most likely something like either <span style="display: none"> or <span style="visibility: hidden">.

The correcsponding displayed tags would then be <span style="display: block"> and <span style="visibility: visible">.

If Config.ISCavailability is a boolean, then I think you want something like this:

<span class="textBlack" style="visibility:<%= Config.ISCavailability ? "visible" : "hidden" %>">

Share:
32,756
Jack M
Author by

Jack M

Updated on July 05, 2020

Comments

  • Jack M
    Jack M almost 4 years

    I have a span that is part of a JSON object and need to set it visible or invisible due to some config options.

    I have the following code but I am struggling to make it work:

    function isc_getsvldata() {
    
            return JSON.stringify(
                {
    
                    polygon_shading_template_hash:
                    {
                        AVAILABLE_3_NONE:
                        {
                            interior: 0x<%= System.Drawing.ColorTranslator.ToHtml(Config.ColourSoldout).TrimStart('#') %>,
                            border: 0x<%= System.Drawing.ColorTranslator.ToHtml(Config.ColourSoldout).TrimStart('#') %>,
                            poly_tool_tip_template:
    
                                 <%= Config.ISCavailability ?"<br><span class='textBlack'> [% @1:((polygon.counters[1] * 100) / polygon.counters[0]); %]%</span>":"<span class='someotherclass'>Nothing</span>"%>
                        }
                    }
                }
            );
    }
    
    • gdoron is supporting Monica
      gdoron is supporting Monica over 12 years
      Ha? What does that code mean?
    • Jack M
      Jack M over 12 years
      That is a code that return a text message depending on the availability(ISCavailability) flag being set to true or false.
    • weltraumpirat
      weltraumpirat over 12 years
      I added .net and asp.net tags, because I assume you're working with those...
  • Jack M
    Jack M over 12 years
    Hi I know about the css option, the config is a boolean value that is set to true or false as different option will make the span visible or invisible.
  • AHM
    AHM over 12 years
    okay, I updated my answer. Just use a tristate or something to output the correct attribute.
  • Jack M
    Jack M over 12 years
    I had previously tried that and it didn't work, still being displayed, I am inclined to thinking that it is due to the JSON.stringfy function that would return something like this{"blabla","blabla"}
  • AHM
    AHM over 12 years
    Are you sure? JSON.stringify() should return excactly what you put into it, so the problem must be somewhere else. What is the markup you end up with inserting (the final markup, not the template)?. You have noted that you were using single qoutes instead of doubleqoutes in the markup in your example, right? You have to use double qoutes, otherwise the html is invalid and the attributes will be ignored.
  • Jack M
    Jack M over 12 years
    Hi, I have edited the question to put the code that works, I was dumb enough not to understand the if