Can we modify CSS using an externally loaded jQuery script?

On my index page, I have SVG code that opens a popup with the .load method containing some HTML and a close button. I am trying to change the fill attribute of an SVG element on the main page when the close button within the popup is clicked, but I'm not sure if it's possible. The external file being loaded is located in a subfolder.

// Main page code to open the popup
$("#isl1").click(function () {
    $("#opdracht").slideDown({
        duration: 300,
        easing: "easeOutBack"
    })
    .load("opdrachten/opdracht1.html");
});


// Close button on external html file
$("#close").click(function () {
    $("#opdracht").slideUp({
        duration: 1000,
        easing: "easeInBack"
    })
    $(this).find('.st7').css('fill', '#ffffff');
});

Although there are no errors, the fill does not change as expected. The code works on the main page, but I was unsure if it would work on a loaded page. Any guidance on how to solve this issue would be greatly appreciated.

Answer №1

By replacing $(this) with $('#my_svg_id'), I was able to solve the issue!

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

Divide the array into distinct characters or verify the presence of a specific character

I have designed 3 buttons with unique names. When button A is clicked, it appends the value to an array. For example: <a href="#" class="answer" data-value="Football">Football</a> Clicking on this button will add "Football" to an empty array. ...

YII2 does not allow passing data through post requests using Ajax

I currently have a standard form on the view, as I'm avoiding the use of an active form due to conflicts with appAsset caused by a jQuery child window. <form id="technician-create-form" method="post"> <input type="hidden" name="csrf" id= ...

Exploring Bootstrap: the ins and outs of customizing styles

How can one determine which bootstrap styles need to be overridden when customizing the appearance? Is there a trick to identifying where to set styles in order for them to take precedence over bootstrap styles? For instance, I've been struggling fo ...

Can I initiate an AJAX call from a different JSP page?

My scenario involves a JSP page that opens another JSP in a new tab. In the second JSP, I upload a file to the server, as I have certain important operations to perform there. However, I also need to include a link to this uploaded file in the first JSP ...

The submit button must be double-clicked in Internet Explorer

The code below is used to submit a form and call a PHP script: <script> function handleBrowse() { $('#uploadedfile').click(); } function displayFilePath(obj) { document.getElementById('dummyFilePath').innerHTML = obj.val ...

Display the dropdown selected value within a Laravel Blade template

I am facing an issue with passing the selected value from a drop-down to another Blade file in Laravel. I have tried using Ajax and jQuery, but it doesn't seem to work for me. I want to display the selected value on the content.blade.php page without ...

Real-time list refreshing using ng-repeat

I am encountering an issue with using ng-repeat in a table to create a folder tree structure. When I click on a specific row and update the value based on a certain condition by calling a function via "onclick" (since ng-click is not working), the JavaScri ...

Reversing JQuery animations can be achieved by using the `

As someone who is relatively new to JQuery and web development, I find myself in need of assistance. Despite researching for a few days, I have not been able to find a solution that meets my requirements. While browsing through various forums, I noticed th ...

Is there a way to set the jQuery MultiSelect widget to be read-only mode?

Is there a way to set Eric Hynds' MultiSelect plugin for jQuery UI to read-only mode? I already know how to disable the widget, but I'm looking to show its contents without allowing any user interactions. ...

Secure your HTML by using PHP to escape characters, then enhance it with jQuery

I am facing an issue where the HTML, stored in a PHP variable (which may vary), fails to be properly appended using the jQuery append function. I have tried using htmlentities, html_entity_decode, and htmlspecialchars functions to format the HTML without ...

Retrieving a variable beyond the scope of jQuery's document.ready() function

I'm feeling quite frustrated and hopeful that someone can assist me with this issue. I don't have strong skills in JavaScript or JQuery (I'm more of a back-end developer), but I've looked everywhere for a solution to no avail. Here is a ...

Turning spring form data into a JSON object via automation (with a mix of Spring, jQuery, AJAX, and JSON)

Recently, I've set up a spring form that utilizes ajax for submission. Here's an overview of my form... <form:form action="addToCart" method="POST" modelAttribute="cartProduct"> <form:input type="hidden" ...

With the power of jQuery, easily target and retrieve all label elements within a specified

Currently, I'm working on developing a function that should be executed whenever any of the labels for a particular group of radio buttons are clicked. So, I need a way to reference all the labels in this radio button group. In my search for a soluti ...

Can someone explain the significance of '{}' within the function shown below?

I've been able to grasp most of this code, but I'm unsure about "{}". Can anyone clarify its meaning? var Toggle = function(section, expand) { this.section = section || {}; this.expand = expand | ...

Include a navigation bar in the footer of my WordPress Theme's footer.php file

Looking for help with adding a custom footer to my WordPress theme. I have successfully uploaded my static website here, and now I am in the process of making it dynamic. I have added my primary menu to WordPress, but I am unsure of how to exactly add a fo ...

How can we ensure all elements in a row are aligned at the top?

My goal is to position the elements in a row, which is enclosed within a container, at the top of that row. Here is the current structure of my HTML: <div class="container"> <div class="row"> <div class="ticket"> ...

I'm wondering why the columns in my Bootstrap 4 grid don't have uniform height and width

Currently, I am utilizing Bootstrap 4 to create a grid view. However, I have encountered an issue where my columns do not have the same width and their heights are uneven, as evident from the borders. It is mentioned that in Bootstrap 4, columns should inh ...

My goal is to utilize vanilla JavaScript to highlight the anchor that was clicked and then remove the highlighting from any previously highlighted anchor

Hello everyone, this is my first time posting here and I'm still trying to figure things out, so I appreciate your patience. Currently, I am experimenting with vanilla JS to create a functionality where clicked anchors are highlighted while removing ...

What is the best way to add a numbered alert to a button using HTML5, jQuery, PHP, or JavaScript?

I have a button on my HTML page that directs users to a page containing email features. I'm looking for a way to show users the number of unread messages they have before they click on the button to view them. I want this to be a subtle alert without ...

The Nodejs express static directory is failing to serve certain files

Hello everyone, I'm currently working on a project using NodeJs, Express, and AngularJS. I've encountered an issue where my page is unable to locate certain JavaScript and CSS files in the public static folder, resulting in a 404 error. Strangely ...