Using JQuery to manipulate content with pseudo elements

I'm attempting to modify the arrow displayed in an :after pseudo element.

Here's my CSS:

legend:after {
    content: url('/html/img/arrow-fieldset-up.png');
}

I am trying to change it with the following JavaScript/jQuery:

$('legend', selected_fieldset).attr('content','url(/html/img/arrow-fieldset-down.png)')

Answer №1

To target the pseudo element using jQuery, you will need to apply a class in your CSS:

legend.selected:after {
    content: url('/html/img/arrow-fieldset-down.png');
}

Then, simply add this class whenever you want to alter the content, such as when clicking on the legend:

$('legend').click(function() {
    $(this).addClass('selected');
})

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

Error message: "Invalid context validation for CFSELECT tag when utilizing it within a JavaScript function"

When I run CFSELECT normally it works fine, but when I try to include JavaScript inside it, I encounter an error. The normal version works as expected. <tr id='selectionDropdown'> <td >Non-Keyword Traffic:</td> <t ...

Retrieve the parseJSON method using a string identifier

I am trying to serialize a C# const class into name-value pairs, which I need to access by their string names on the client side. For example: return $.parseJSON(constantClass).property; This approach is not working as expected. Is there any alternative ...

Resizing objects within a section to conform to the section's dimensions is not possible in CSS/HTML

I'm facing some challenges with responsiveness on my landing page. Utilizing the scrollify jQuery library, users can skip between different sections of the landing page on click or scroll. However, when switching to landscape orientation on mobile d ...

Manipulating CSS rules using JavaScript/jQuery

My goal is to create a function that generates a grid based on table data. While the function itself seems to be working, I am encountering an issue where the classes applied are not resulting in any style changes. Below is a snippet of my function: $(doc ...

Guide on showcasing an icon adjacent to the input fields once they have been validated successfully with the help of jquery plugins

I am struggling with the code below which is supposed to validate the SubmitForm when the button is clicked. It successfully changes the textboxes to red and displays an error message with a symbol if validation fails. However, I am wondering how I can sho ...

Synchronize the quantities of two products in the WooCommerce cart

I need help syncing two product IDs in Woocommerce's cart so that changing one will automatically change the quantity of the other. However, the code I am using updates all products in the cart with the master product ID, which is not the desired outc ...

Show the variable in the input field without relying on the value attribute

I've been struggling to display a PHP variable in an input field without using the 'value' attribute. I attempted to use a jQuery code that I found, which was supposed to 'append' the variable to the input field, but it didn't ...

What methods are available for testing JavaScript interactions like freehand drawing on an HTML5 canvas using a mouse?

When it comes to testing object states, I am well-versed in using rspec in Ruby on Rails models. For instance, ensuring that a certain object meets certain expectations based on its prior state and a specific call. However, I am now faced with a new chall ...

"Implementing a click event handler on a button within an iframe

On my website, I have embedded an iframe containing external content. Within the code of this iframe is a button identified by the id "XYZ." I want to create an onclick function for this button. Here's what I've attempted: $( "#XYZ" ).click(fun ...

Utilizing Jquery to Incorporate an Input Field and Datepicker Feature

Having trouble getting the jQuery datepicker to work on my input field. I attempted the following: $(function() { $('.datepick').each(function(){ $(this).datepicker(); }); }); The input field generated by jQuery: <input name="date[]" ...

The jQuery scroll function is not working for the span class I specified. What could be causing this issue?

I attempted to implement a scroll-to plugin to move between elements on a page when clicking previous and next buttons. The source demo works differently from my modified version, and I am struggling to figure out where I went wrong. Source demo: My Curr ...

center text vertically in HTML list

Here at this festival, you'll find a unique menu on the sidebar. The menu is created using an HTML list with the following structure: <ul class="nav nav-pills nav-stacked"> <li class="active"> <a href="index.html"><i ...

Implementing a JQuery function to generate a popup whenever a user clicks on a table row (tr) in an

I am working on a JSP page that contains a table, and I want to implement a pop-up window functionality when clicking on a specific row in the table. I have attempted to use JavaScript to connect with the row but so far, I have not been successful in creat ...

create a division in the organization of the identification numbers

Is there a way to always change pages when the id changes in a foreach loop to separate the printed pages? Take a look at this code snippet: var data = [ {Id: "552", valor: "50.00", Descricao: "Fraldas", }, {Id: "552", valor: "35.00", Descrica ...

The data retrieved by the $.getJSON method is not displaying as a line graph

I am currently dealing with two files searh_journal.php <script type="text/javascript"> function submitForm() { var form = document.myform; var dataString = $(form).serialize(); $.ajax({ type: 'POST', url: & ...

When I click on the icon, I wish for it to revert back to its original state by spinning

Is there a way to revert the icons back to their original state when clicked again, without losing any of the current functionalities? When an icon is clicked for the first time, it rotates 180 degrees. The icon rotates back if another icon is clicke ...

Tips for aligning a textbox and label in the same row with Bootstrap

Is there a way to align two text boxes and a drop-down in the same row while displaying labels below them? I want the layout to look like this: https://i.sstatic.net/eQZnn.png Currently, my code is displaying the text boxes stacked on top of each other. ...

Adjusting the width of individual cells or columns within a table through my HTML code is proving to be a challenge

I am struggling to adjust different column widths in my table. Despite trying various approaches, such as changing the width of specific td/th elements and using inline styling or nth-child property, I have been unsuccessful in altering the width. The tabl ...

Modal - sending data through URL

I am trying to create a modal that will open another view using a URL in script, but instead it just opens a blank pop-up and doesn't redirect to the URL. I have attempted various approaches, but none seem to be working. Adding <div class="modal-b ...

What is the best way to increase margin beyond mt-5 or mb-5 in Bootstrap 4?

I am working on a form and would like to set its margin-top to 100px. Is it possible to achieve this using Bootstrap classes, or do I need to create a custom class for it? <form class="mt-5"> </form> It seems that the maximum margin-top I ca ...