Ways to display or conceal a moving svg based on the current tab selection

Below is the fiddle and snippet: https://jsfiddle.net/e130kr2x/

I've successfully achieved animating the SVG when a tab is active, but I'm facing difficulty in making it not display or fade out when opening a new tab. The new tab should activate and animate the SVG one after another.

-- First query: Is there a CSS-only approach instead of embedding the SVG in every tab in the HTML? I considered using the image attribute, but it doesn't support animation.

-- Second query: The SVG animation stays under inactive tabs. How can I make it hide or fade out when a tab is inactive?

Additionally, I'd appreciate guidance on moving my JS script from the HTML file to a separate JS file. I am new to JS, so thank you for any advice.

#my-tab{
`      margin-top:20px;
   overflow:hidden;
   display:block;}
 
   <!-- More CSS code here -->

<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>

<!-- More JS script here -->

<div class="product-description" itemprop="description">

<div id="my-tab" class="my-tab">

<ul class="tabs">

<!-- Embedded SVG contents here -->

  

Answer №1

To set the display attribute depending on whether the tab is marked as .active, you can do the following:

<style>
  #my-tab ul.tabs li a svg {
    display: none;
  }
  #my-tab ul.tabs li a.active svg  {
    display: block;
    height: auto;
  }
</style>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method for retrieving text that does not contain tags (such as text

My challenge involves storing headings and paragraphs into separate arrays, but I am struggling with handling text between <br>. Below is my HTML code and Python snippet: <p><strong>W Ognisku</strong><br>W londyńskim Ognisku ...

Using jQuery to add a class to an input option if its value exists in an array

Looking for a way to dynamically add a class to select option values by comparing them with an array received from an ajax call. HTML <select id="my_id"> <option value="1">1</option> <option value="2">2</option> ...

Angular components are not properly adhering to the specified height and width dimensions for child elements

I seem to be having trouble applying height/width to a child component in angular. Can someone take a look and point out where I may have gone wrong? app.component.html <app-child [width]="10" [height]="10"></app-child> .child.ts import { C ...

Craft a dynamic menu of categories using PHP

As a beginner in coding and PHP, I am working on creating an online shop for a school project. I am looking for a simple code that can select categories from my database and display them on the homepage. Additionally, when a user clicks on a category, I ...

Calling ASPX method remotely and receiving undefined data

I'm still fairly new to ASP.NET and web services. I've encountered an issue where I am calling a web service from a *.aspx page, and the web service is returning the correct output. However, when I call the *.aspx method from an external HTML pag ...

At times, the CSS fails to load at first and does not refresh correctly when using F5 or CTRL F5, yet it occasionally loads when clicking on links

After dedicating a full day to trying to solve this issue, I am reaching out for some assistance. As a newcomer here, I apologize if this question has been asked before (I did search extensively and found nothing). The website I'm constructing for my ...

tips for aligning text to the right of an image

For my college project, I am working on a website. However, I have encountered an issue with using a jsp script to display products in a specific way on the webpage. The problem is that I cannot control where the information about price, name, and descript ...

Can someone please help me convert this jQuery code into vanilla JavaScript?

My Cordova app has an email sending function that utilizes jQuery. During debugging, the ajax function works perfectly in my browser, but once I build the app and test it on my phone, it stops working. I encountered a similar issue before, which was resolv ...

Is It Possible to Use Separate Stylesheets for Different Web Browsers?

I have been trying to implement a JavaScript code that loads a specific stylesheet based on the user's browser. However, it seems like the code is not functioning correctly as none of the stylesheets are being displayed. I have meticulously reviewed t ...

In a remarkable design with an array of buttons and an individual div assigned to each, a fascinating functionality unfolds. Whenever a

https://i.stack.imgur.com/emhsT.png When I click on the first "Respond" button, I want the adjacent text box to disappear. Currently, if I click on the first "Respond" button, both text boxes will disappear instead of just the first one. $('.comment ...

Unable to generate this QUIZ (JavaScript, HTML)

Hi there, I'm working on a sample quiz and having trouble displaying the result. As a coding newbie, I could really use some help. In this quiz, users answer questions and based on their responses, I want to display whether they are conservative, agg ...

Steps for inserting telephone numbers from a database into an <a href="tel:"> tag

<a href="tel:<?php echo $b2b_mec_num; ?>"><button type="button" class="btn" id="CallBtn">&nbsp;CALL</button></a> I am looking to dynamically add phone numbers from a database to the anchor tag provided in the code snippet ...

What are the best methods for preserving paint color when changing wheel styles, and vice versa?

I posted this query about a year ago, but I did not have a fiddle prepared at that time and my question was not as well articulated as it could have been. Despite that, many people came forward to offer their help, and I am truly grateful for that. This ti ...

Update dynamically generated CSS automatically

Is there a way to dynamically change the CSS? The problem I'm facing is that the CSS is generated by the framework itself, making it impossible for me to declare or modify it. Here's the scenario at runtime: https://i.sstatic.net/IovGr.png I a ...

"Create a dynamic and user-friendly responsive navbar using Bootstrap with toggle

I need assistance with creating a new project template to convert a WordPress template into a Bootstrap template. Currently, I am working on the navbar and facing issues with responsive design and toggle navigation. On laptop devices, the navbar looks goo ...

Align the prices of products in a uniform position within each table cell

Apologies for the lengthy explanation. I am working with osCommerce and have a page that displays all our product specials in a 3 column table layout. My challenge is to align the price of each product so that they are aligned perfectly across the screen. ...

"Automatically scroll back to the top of the page once new content

Is there a way to automatically scroll the page to the top after content has been loaded via Ajax? Here is the code I am using to display the content: $(document).ready(function () { var my_layout = $('#container').layout(); $("a.item_l ...

Notification during image loading

I have successfully integrated the Nivo slider on my website, however, I am encountering a minor issue. Whenever the images are loading, it causes the footer to shift upwards which affects the overall look of the site. Is there a simple solution to add a m ...

What is the process for modifying the attributes of a currency text box in a Dojo within XPages?

I have come across several discussions aimed at addressing this issue, but none of them have provided a clear and definitive solution that I can easily follow. Is there a straightforward method to modify the css of a dojo field within XPages? Specifically ...

Having trouble searching using CSS or XPath with Selenium Webdriver, but no issues when searching by ID or class

I am currently using Eclipse Mars along with JDK 1.8. Below is the code I have written: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public cla ...