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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:49:40+00:00 2026-06-03T07:49:40+00:00

See the code below – I am trying to include inline svg in my

  • 0

See the code below – I am trying to include inline svg in my website. I am following a neat suggestion to use the svg switch element so that it degrades gracefully on older browsers. The idea is that browsers which support svg use the first element in the switch block; those which don’t ignore all the svg tags and just show the img buried in the second element (i.e. the foreignobject tag) of the switch block.

It works really well … except that my svg (which is sheet music) necessarily includes text elements and they get rendered (as well as the foreignobject) by older browsers.

Ironically it is easy to deal with this in IE8 and below using conditional comments.

For other older browsers I have a javascript work-around inside the foreignobject which redefines the class of the svg text. It works … but it feels like a real hack.

Is there a better way to do this (better javascript, a css solution, another way of doing the svg text …)?

Anyway here is the bare bones of the code:

<html>
<head>

<!-- this deals with elements using the svgtext class in old IE browsers -->
<!--[if lte IE 8]>
<style type="text/css">
.svgtext { display: none; }
</style>
<![endif]-->
<style type="text/css">
.donotdisplay { display: none; }
</style>

</head>
<body>

<svg ...>
<switch>
<g>
<!-- the svg goes here -->
<text class="svgtext">this gets rendered unless I deal with it</text>
</g>
<foreignObject ...>
<script type="text/javascript">
window.onload=function(){
  var inputs=document.getElementsByTagName('text');
  for(i=0;i<inputs.length;i++){
    inputs[i].className='donotdisplay';
  }
}
</script>
<!-- the replacement img tag goes here -->
</foreignObject>
</switch>
</svg>

</body>
</html>
  • 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-03T07:49:42+00:00Added an answer on June 3, 2026 at 7:49 am

    Here’s an idea for for browsers other than IE8 and earlier (which need the JS based shiv to recognise the text element.) for a CSS-only solution,

    <!DOCTYPE html>
    <html>
      <head>
        <title>Test Case</title>
    
    <!--[if lte IE 8]>
        <script type="text/javascript">
          document.createElement("text");
        </script>
    <![endif]-->
    
        <style type="text/css">
          @namespace svg "http://www.w3.org/2000/svg";
          text { display: none; }
          svg|text { display: inline; }
        </style>
      </head>
      <body>
    
        <svg>
          <switch>
            <g>
              <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
              <text x="20" y="120">this gets rendered unless I deal with it</text>
            </g>
            <foreignObject>
              <p>Use an SVG capable browser</p>
            </foreignObject>
          </switch>
        </svg>
    
      </body>
    </html>
    

    The idea here is that browsers that support SVG inline, do so by putting the SVG elements into the “http://www.w3.org/2000/svg” namespace, which can then be addressed in the css.

    Tested in Firefox 12, IE9, Chrome 18 Opera 11.6, which show the SVG, and Firefox 3.6 and Safari 5.0 which show the fall-back.

    JSFiddle at http://jsfiddle.net/rGjKs/

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

Sidebar

Related Questions

Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
I am attempting to use the MediaStore.ACTION_VIDEO_CAPTURE in my app, see code below. However,
I have an input element that's configured as a button (see code below). When
Im trying to connect a Information object to many Customers (see code below) When
Can't seem to figure this out, see code below. Trying to make a GET
See code below: I want Page 1 to alert #testing... This works in C
I am using vb.net code. I have grid view, please see the code below:
I've a problem with CakePHP __() function. Please see the code below : $options
I am having a problem using the signedCMS.decode routine. See the code below. The
Technology Used:- Asp.Net 2.0 Code:- See Below Description:- hello code given below is working

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.