Tips for modifying text by filtering it and substituting it with alternative content

I have a website's contact page where there is a phone number and I want to create a code that can identify this specific phone number and replace it with a new one.

Below is the code snippet:

<div class="elementor-widget-container">
    <h2 class="elementor-heading-title elementor-size-default"><b style="">Phon</b>e</h2>
</div>

<div class="elementor-element elementor-element-071bea1 elementor-widget elementor-widget-heading is-mac" data-id="071bea1" data-element_type="widget" data-widget_type="heading.default">
    <div class="elementor-widget-container">
        <h2 class="elementor-heading-title elementor-size-default">888-299-1979</h2>
    </div>
</div>

Answer №1

In CSS, filtering for content is not directly possible. However, there is a workaround that involves adding content through an attribute and displaying it using a pseudo-element.

Here's how you can do it:

span[number]::after {
  content: attr(number);
}
<span number="888-299-1979"></span>

You can also "search" for the content and modify it in this way:

/* "searches" the number */
[number="888-299-1979"]::after {

  /* changes the number */
  content: "xxx-xxx-xxxx";  
}
<span number="888-299-1979"></span>

Answer №2

Are you looking to use CSS to locate a phone number on your website and then replace it with a different phone number?

Surprisingly, CSS cannot actually search for a specific phone number on your website. To achieve this, you will need to utilize a selector in your CSS.

Here is your code block with an added ID:

<h2 class="elementor-heading-title elementor-size-default" id="phone-number">888-299-1979</h2>

Your CSS:

#phone-number {
    visibility: hidden;
}

#phone-number:after {
    visibility: visible;
    content: "123456789"; //enter your new phone number here
}

Alternatively, you can achieve the same result without using CSS by utilizing JavaScript [RECOMMENDED]:

document.getElementById("phone-number").innerHTML = "your_new_phone_number_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

The Syntax of 2D Transformations

I am currently attempting to apply multiple animations on a single element simultaneously. While I have successfully managed to use the translate property to adjust the element's coordinates, I am encountering difficulties in expanding its height and ...

Eliminating unnecessary whitespace between the bottom of the document and an element

I have a HTML page that when scrolled should limit scroll to the document height. It must not exceed the bottom of an element. Here is a screenshot for better understanding: https://i.stack.imgur.com/RaVg8.jpg The scrolling should be limited after the En ...

Retrieving the information verified in the database

public function actionEditmul($id) { $sql1="SELECT * FROM category_product INNER JOIN category ON category_product.cat_id=category.cat_id WHERE category_product.product_id=$id"; $editcat=Yii::$app->db->createCommand($sql1)->quer ...

Unable to swap out image when hovered over

This is a new issue for me, as I can't seem to understand why the hover effect is working, but the background image won't change: <div class="settings" id="settings" style="background-image:url(assets/settings.svg);&qu ...

Expanding a div to occupy 100% width within a Material UI TableBody

I am struggling to center a CircularProgress component inside a material UI TableBody. I have attempted the following code, but the CircularProgress is not displaying at the center as expected. (Please note that only relevant code has been included) const ...

How to Remove a CSS Class from an <li> Tag in ASP.net Using Code Behind

Currently, I am adding a CSS class to my li tag using the following code snippet: liComPapers.Attributes.Add("class", "NoDisplay"); Is there a way to remove this specific class (NoDisplay) from the li tag at a different location in my code? I have attem ...

Switch out 2 Bootstrap columns for 2 concealed columns with just a click. Utilizing Rails 4 and Bootstrap

Using Twitter Bootstrap 3 for a column system showcasing four similar advertisements at the bottom of the page. Code Snippet: <div class="row similar"> <% @recomended_ads.each do |advertisement| %> <div class="col- ...

Guide on toggling the button by clicking on the icon to turn it on or off

Within my angular application, I have implemented font icons alongside a toggle switch. Initially, the switch is in the ON state. The specific functionality desired is for clicking on an icon to change its color from white to red (this has been achieved) ...

Aligning SVG shapes within each other

I recently encountered a scenario where I needed to position SVG shapes in the center of each other with varying scales. For instance, placing a rectangle or triangle within the center of a circle. While I found some solutions that worked for shapes like ...

Showcasing Information Using AngularJS from a Json Array

My goal is to present data from a JSON array in a table using the code below. However, all the data is currently being shown in one row instead of each record appearing on separate rows with alternating colors - grey for even rows and white for odd rows. I ...

Using jQuery to Generate an Automatically Updating Timer for Slideshow - Pausing on Mouse Click

My first slideshow with jQuery is up and running, but it's very basic and hard coded. I want to add an automatic scrolling effect every 8 seconds to the next item before looping back to the beginning. I have an idea on how to achieve this, but I want ...

The error alert must be displayed directly beneath the specific box

When error messages occur in this code, they are displayed through an alert box. However, I would prefer to have the error message appear below the specific text box instead. This means that when I click on the submit button and a field is left empty, the ...

Determine the total quantity of colored cells within a row of an HTML table and display the count in its own

I need assistance with a table that has 32 columns. From columns 1 to 31, I am able to fill in colors by clicking on the cells. However, I now want to calculate and display the number of cells that are not colored in the last column. This task must be co ...

The navigation bar and footer are not utilizing the entire width of the browser

Something seems off on the Safari browser, as there's still a gap in the right side of the navbar and footer. I've been using Bootstrap and steering clear of Javascript. Any ideas on how to fix this? Appreciate any help. Thanks! Here's the ...

Experimenting with creating collapsible panels using Bootstrap/CSS can result in various outcomes

, I am in the process of constructing a collapsible sliding left panel using bootstrap 5. The progress has been notable, but I am encountering some hurdles. Upon reviewing the code at this link: https://jsfiddle.net/dizzy0ny/86wjas9L/108/, you will witness ...

What steps can be taken to create a seamless navigation experience that effectively emphasizes the user's current location?

Is there a way to dynamically add the "current" class to the navigation menu based on the user's current location on the page? This would make it easier for users to see which section of the site they are viewing as they scroll through. Check out this ...

Optimize HTML outputs in Smarty by reducing the file size

Is there a way to minify all output HTML templates in Smarty automatically? Would it be possible to set something like this: $smarty->minify = true; Additionally, I have come across the {strip} function but using it in every single .tpl file is not fe ...

Is it possible to create HTML content directly from a pre-rendered canvas element or input component like a textbox?

As I delve into learning JavaScript and HTML5, a couple of questions have sparked my curiosity: 1) Can we create HTML from a Canvas element(s)? For instance, imagine having a Canvas shape, and upon clicking a button, it generates the HTML5 code that displ ...

CSS - maximize the contrast between background and foreground colors in order to enhance

I'm dealing with a bar column that changes color based on the percentage value. However, some of the text is not visible to users because it falls within the white section of the bar. When selected, the text becomes visible but not otherwise. Is the ...

I cannot seem to receive the confirmation of success!

Trying to store user details in a database and display a success message that fades in. I have attempted some code, but unfortunately it's not working. Please help me out. Apologies if I am mistaken. Here is my register.php code: <?php require ...