Initiate CSS-Transitions using JavaScript

Despite reading 5 tutorials on how to initiate a CSS-Transition with JavaScript, I am unable to get it to work properly. My current browser is Safari. Below is the code that I have been working on:

<html>
<head>
<title>Test</title>
<style type="text/css">
    #test{
        width: 100px;
        height: 100px;
        background-color: aqua;
        transition: width 3s linear;
    }
</style>
<script type="text/javascript">
    function test(){
        document.getElementById('test').style.width = 200+'px';
    }
</script>
    </head>
    <body>
      <div id="test">
      </div>

      <button onclick="test()">Los</button>
    </body>
    </html>

Answer №1

It might be necessary to utilize vendor prefixes; Safari uses webkit, so consider adding the -webkit- prefix.

<style type="text/css">
    #test{
        width: 100px;
        height: 100px;
        background-color: aqua;
        -webkit-transition: width 3s linear;
        -moz-transition: width 3s linear;
        transition: width 3s linear;
    }
</style>

Check out the DEMO here

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

Utilizing Ajax Success Function with Distinct Div Element Identifiers

My question is a bit complex. I have a while loop that goes through an SQL query and displays all the articles found in the database. <div class='dislike_box'> <a href='#' class='counter'> <im ...

The toggle button appears to be lacking in CSS styling

I'm trying to create a dropdown button using Bootstrap and ng-bootstrap in my Angular project. Here's the HTML I've written: <div ngbDropdown class="d-inline-block"> <button class="btn btn-outline-primary" id="dropdownBasic1" n ...

How to programmatically unselect an ng-checkbox in AngularJS when it is removed from an array

Utilizing checkboxes to gather values and store them in an array for dataset filtering purposes. The objectives are as follows: Show child filters when parent category is selected. Unselect all children if parent is unselected (otherwise they will ...

How to prevent redundancy in CSS styling

Exploring CSS on my own and have the following HTML structure: <style type="text/css"> #content { display: block; width: 250px; height: 50px; background-color: #330000; } /* pink */ #one, #two, #three, #four { height: 25px; width: 25px; float: left ...

The Iframe is loading a JavaScript that is already loaded on the parent page but is not being fetched from the disk cache

My webpage has 4 iframes, all loading the same javascript file. However, when I checked the network tab in my browser's developer tools, I noticed that the javascript was being loaded 5 times from the server. I tried to set the iframes to load only af ...

Unlocking the secrets of integrating Vuex store with JavaScript/TypeScript modules: A comprehensive guide

I am working on a vue application and I have a query. How can I access the store from javascript/typescript modules files using import/export? For example, if I create an auth-module that exports state, actions, mutations: export const auth = { namesp ...

Most effective method for removing or emptying Ajax "temporary" items in Internet Explorer 7

Could someone inform me if I have to clear the "temp" files every time I execute the ajax process in php? ...

What could be the reason for the CORS failure when making requests from an HTTPS domain to an HTTP localhost

I have a secure rest service (implemented as an Azure Function), hosted on HTTPS, under domain A. My website is also running securely on HTTPS but on domain B. I've set the CORS to use a wildcard *. Using jQuery on my website, I send Ajax requests ...

Text swapping out javascript jquery

Greetings to all, and my apologies for any language mistakes. I am seeking assistance and guidance from this community. Yesterday I came across a post (here) regarding string substitution. Let's simplify things by removing the tables and focusin ...

Issue: `Alert` not triggering after clicking on anchor link in AJAX response

Below is the code I am currently working with: $('.ver').click(function(e) { e.preventDefault(); var id = $(this).next().val(); $.post('cotizar_detalles.php', {'id': id}) .done(function(response) { ...

Provide the identification number of a specific row within the modal

I am trying to pass the id of a specific row into a modal popup Link code: <a href="#myModal" class="btn btn-default btn-small" id="custId" data-toggle="modal" data-id="<? echo $row['id']; ?>">Resume</a> Modal code: <div ...

Is it possible to generate a "pop-up" window upon clicking on the register button?

As a backend programmer, I'm looking to create a popup window that appears in front of the current window when users click "register", eliminating the need for redirection to another page. I believe you understand the concept. How can I achieve this? ...

Tips for transferring a variable from a webpage's JavaScript to Node.js

Having an issue with transferring a Javascript variable to node js for JSON file storage. The data doesn't seem to be writing to the file, possibly due to an error in the AJAX Post request or the node JS routing. The javascript is executed on an HTML ...

Is there a way to restrict the number of line breaks in a multiline asp:TextBox control?

Is it possible to restrict a multiline asp:TextBox to only display content on 3 lines using either javascript or C#? ...

Having trouble retrieving information from .pipe(map()) method

Encountering some issues with Observable handling. I have a function that returns an Observable. public getData(userId) { const data = this.execute({userId: userId}); return {event: "data.get", data: data} } private execute(input: SomeDt ...

Clarification on Regular Expressions

Looking to improve my java-script code for extracting words that occur after an "=" in a string. For example: string strOld="ActionDate=11/20/2014 12:00:00 AM "; strOld.substr(strOld.indexOf(type)).substr(type.length +1, strOld.substr(strOld.indexOf(typ ...

Preserve the output from the jQuery ajax request

I have created a custom function that calls an ajax request and saves the response data to a variable before returning it. It always shows '0' as the return value, but the alert displays numbers like 3712. Below is the implementation of the func ...

Implementing a Moving Background Image with CSS3 or jQuery

I am facing an issue with a background image that has a file size of 4+ MB in PNG format. My website is a single page website and I want to use this background image, but I'm unsure how to go about it. Is there a way to reduce the size of the image s ...

After submitting the form, Axios sends multiple requests simultaneously

Recently, I embarked on a small project that involves using Laravel and Nuxt Js. The main objective of the project is to create a form for adding users to the database. Everything seems to be progressing smoothly, but there's a minor issue that I&apos ...

Exploring the wonders of ReactJs in the ComponentDidMount

I am encountering some issues with my app. Although I am not a Javascript expert, it seems like an easy fix to me. I need to make the following call: this.props.onNavStyleChange(NAV_STYLE_FIXED); to change the navigation when this page loads. However, I ...