Modify HTML style content

Here's an excerpt from my CSS file:

.pricing .pricing-value .price:before {
  position: absolute;
  content: 'different text';
  top: 10px;
  left: -35px; }

I'm wondering if it's possible to change 'different text' to something else using inline styles in my HTML file. For example:

<span class="price" style='new_style_here'>

Answer №1

To dynamically alter the content of pseudo-elements, you have the option to use content: attr(some-attribute)

span:before {
  content: attr(data-text);
}
<span data-text="Append"> TEXT</span><br/>
<span data-text="Another"> TEXT</span>

Answer №2

Actually, no. The ::before pseudo-element cannot have styles applied directly to it using the style attribute because it is created after the DOM has been constructed.

One alternative solution is to add a new class and modify the text within that class. For example:

.info .value .label.new-text::before {
    content: 'new text';
}

<span class="label new-text">

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

Acquiring administrative authorization upon user login with PHP

I have developed a registration form and a login form using PHP. However, whenever I run this code, it displays the message "invalid username" when the username is invalid, or it says "your account isn't approved by admin yet." Can anyone please guide ...

Skip ahead button for fast forwarding html5 video

One of the features in my video player is a skip button that allows users to jump to the end of the video. Below is the HTML code for the video player: <video id="video1" style="height: 100%" class="video-js vjs-default-skin" controls muted autoplay=" ...

Navigate to the end of the chat window using AngularJS

Is there a way to automatically scroll to the bottom whenever a new message is received? I have code that moves the scrollbar, but it doesn't go all the way to the bottom. Can someone please help me with this? Here is my code on Plunker: http://plnk ...

"Unable to get 'vertical-align middle' to function properly in a table

Can someone please review my code at http://jsfiddle.net/4Ly4B/? The vertical alignment using 'vertical-align: middle' on a 'table-cell' is not centering as expected. ...

Attempting to include a standard VAT rate of 5% on the invoice

/* The code format is correct and I don't see any issues on my end, I hope it works well for you. */ I need assistance in adding a fixed VAT (tax) rate of 5%. The tax amount should be displayed on the row, while the total tax should reflect the sum o ...

Attaching a click event to an input field

Seeking to serve html files from the server without relying on template engines. Below is the script used to start the server. // script.js const express = require("express"); const bodyParser = require("body-parser"); const app = express(); app.use(expr ...

Smartphone screen cluttered with overlapping paragraphs

I am encountering a paragraph overlap issue while using a bootstrap template, specifically on smartphones like iPhone 6 with Safari. Interestingly, the problem does not appear when testing on a browser by shrinking the window size to the minimum. On the ph ...

Establishing a primary color for all text in Vuetify

How can I set a base color for all text in a Vue + Vuetify project? I attempted to change the theme's primary color in vuetify.ts: export default new Vuetify({ theme: { themes: { light: { primary: "#E53935", }, }, }, } ...

Exploring the functionalities of jQuery and Local Storage: Understanding the Selector's various states

I am currently developing a new feature for font customization on a website. The drop-down menu offers several font options to choose from. When a user clicks on one of these options, the following code is executed: jQuery(function($) { if (localStorage.g ...

Is there a way I can ensure the values are loaded when the page loads, rather than displaying NaN?

I've recently created a car rental calculator for a client, and it's almost complete. Everything is working smoothly, from the calculations to the conditions. However, I'm facing an issue where the price isn't calculated on page load. I ...

Hiding a Hide/Show DIV when hovering over the Google+ Follow Button

I'm currently working on a project that involves a hover drop-down panel with Google+, Facebook, Youtube, and Twitter social widgets. These widgets are listed for visitors to easily click on each one without the panel closing. Initially, I created a ...

The Info button in Bootstrap5 is sporting a sleek combination of blue background and black text, deviating from the traditional blue and

Check out my full code for the Random Quote Generator Project on Codepen: here I implemented Bootstrap5 from this link: Bootstrap CDN. The button style btn-info is not displaying correctly in my project. I'm puzzled and would like to understand why ...

"Internet Explorer naturally selects the submit button when users press the enter key to submit a

In my current application, I have implemented a form with a hidden button to address issues with the numeric keyboard on Android. Essentially, pressing enter or focusing on the invisible button will trigger form submission. Pressing enter works fine in Ch ...

Ways to trigger a modal programmatically in the backend code?

My goal is to trigger the display of a modal when a button is clicked. The modal should be shown by clicking this button: <asp:Button ID="Button4" runat="server" class="btn btn-info" data-toggle="modal" OnClientClick="return false;" data-target="#View1 ...

Incorporate a lesson featuring jQuery into your curriculum

Just starting out with jQuery and I have a form setup like this: <select name= "menus"> <option value="">--Select--</option> <option value="a">a</option> <option value="b">b</option> <option val ...

Clicking on the Bootstrap tabs causes them to shift position

I have come across an unusual issue with my website. While on the home page, clicking on a tab functions normally. However, when attempting to switch from one tab to another (such as News to Beats, Beats to News, News to Home, or Beats to Home), the tab co ...

Customize Angular Material's Mat-Dialog background blur/darkening effect

Greetings, dear community members, I am currently utilizing angular along with angular material in my projects. By default, when a material dialog is opened, it slightly darkens the background. However, I am interested in having a blurred background inst ...

Troubleshooting problem with CSS background image

I'm looking to make my webpage more dynamic and interactive. One issue I have is that the background image of the body element stretches when new elements are added, which is not the desired behavior. Any suggestions on how I can fix this? <styl ...

"CSS Troubleshooting: Why Isn't My Background Image

Could someone assist me in understanding why this code is not functioning properly? I have experimented with both background-image and background properties, as well as adjusting the height and width attributes. <html> <head> <link ...

Chrome not handling text wrapping within table cells properly

I'm facing an issue with a table I created using the bootstrap stylesheet. For some reason, the cells are not wrapping correctly in Chrome, although they display perfectly fine in IE and Firefox. You can check it out here: <form action="todos" m ...