Update the content of an HTML element without having direct access to the HTML code

I am currently in the process of creating a website using a website builder, and I am interested in customizing the default message that is displayed when a required field in the website form is left empty. The form in question is an integral part of the website builder platform.

Is there a method to modify HTML text without direct access to it?

While I can add code to the <head>, I am unsure if it will impact existing code.

The specific paragraph I aim to alter is as follows:

<div data-v-3a756488=""><p data-v-3a756488="" class="input__error-message z-body-small"> Esse campo é obrigatório </p></div>

In exploring potential solutions, I have considered utilizing CSS to hide the default text within the HTML and supplementing it with alternative content using the content property, although I acknowledge this may not be the optimal approach.

Within the constraints of the platform, I have the ability to leverage CSS, HTML, and JavaScript, as these languages are supported within the <head> and embedded code elements on the site.

Answer №1

Start by attaching an eventListener to ensure that all DOM elements are loaded using

window.addEventListener('load', ...
. Then, select the specific element you wish to modify. In this example, I targeted a paragraph with a data-attribute, assuming it is a unique element with that attribute:
document.querySelector('p[data-v-3a756488=""]')
. Next, use textContent to replace the text within that element:

window.addEventListener('load', function() {
  let ele = document.querySelector('p[data-v-3a756488=""]');
  let text = 'This is the new Text';
  ele.textContent = text;
})
<div data-v-3a756488=""><p data-v-3a756488="" class="input__error-message z-body-small"> This field is required </p></div>

If there are multiple elements that require their text replaced, you can create an array of objects utilizing the same approach. List the elements you want to target along with the corresponding replacement text in the array of objects. Utilize a for-loop to apply the changes specified in each object:

window.addEventListener('load', function() {
  const replace = [
    { element: 'p[data-v-3a756488=""]',
      text: 'new text for first element'
    },
    { element: 'p[data-v-3a756500=""]',
      text: 'new text for second element'
    },
    { element: 'p[data-v-6a756488=""]',
      text: 'new text for third element'
    }
  ];
  
  for (let i = 0; i < replace.length; i++) {
    let ele = document.querySelector(`${replace[i].element}`),
        text = replace[i].text;
    ele.textContent = text;
  }
})
<div data-v-3a756488=""><p data-v-3a756488="" class="input__error-message z-body-small"> This is Element 1 </p></div>

<div data-v-3a756500=""><p data-v-3a756500="" class="input__error-message z-body-small"> This is Element 2 </p></div>

<div data-v-6a756488=""><p data-v-6a756488="" class="input__error-message z-body-small"> This is Element 3 </p></div>

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

In responsive design, the sidebar may be positioned either above or below the content, depending

Managing the placement of a sidebar in a responsive design can be tricky, especially when the sidebar content is crucial on some pages but not on others. One solution may involve switching the order of div elements in the HTML code, but this approach might ...

Warning: When VueJs OnMount props is utilized, it might display a message stating, "Expected Object, received Undefined."

This is my current component setup: <template> <Grid :items="items" /> </template> <script setup> import { ref, onMounted } from 'vue' import Grid from '@/components/Grid.vue' import { getData ...

What is causing the child table (toggle-table) to duplicate every time a row in the parent table is clicked?

After creating a table containing GDP data for country states, I've noticed that when a user clicks on a state row, the child table displaying district GDP appears. However, there seems to be an issue with the child table as it keeps repeating. I&apos ...

A guide to converting variables into a JSON Object in Javascript

I am looking for a way to insert external variables into a JSON object. An example of what I want: var username = "zvincze"; And then, using that variable to inject it into a JSON object: var json = '{"username":"VARIABLE_GOES_HERE"}' var obj ...

What is the best way to personalize the Window.Confirm() dialog in JavaScript?

var val= confirm("Are you sure to cancel?"); The code snippet above will display a popup with two choices - Ok and Cancel, with Ok being the default choice. Is there a way to make Cancel the default choice instead and switch the positions of the ...

Adjust jqGrid dimensions automatically as browser window is resized?

Does anyone know of a method to adjust the size of a jqGrid when the browser window is resized? I attempted the approach mentioned here, but unfortunately, it does not function correctly in IE7. ...

Show only the items in bootstrap-vue b-table when a filter is actively applied

How can I set my bootstrap-vue b-table to only show items when a filter is applied by the user (i.e., entered a value into the input)? For example, if "filteredItems" doesn't exist, then display nothing? This is primarily to prevent rendering all rows ...

What is the best method for choosing the next item with jQuery?

I am facing an issue while trying to apply some design on the next element. The error message that I am encountering is: Error: Syntax error, unrecognized expression: [object Object] > label Below are my selections for browsing by category: BROWSE BY ...

Guide on establishing a connection with a TCP server and sending a JavaScript script to it

I am completely new to JS and node. I am using SkyX Pro, a telescope management software that has the capability to run a TCP Server on port 3040. By connecting with Netcat and providing it with Javascript starting with //* Javascript *//, I can control ca ...

The combination of Angular Hottowel's 'blocks.exception' and 'blocks.router' prevents the App from being displayed in the browser

After delving into Angular's fundamentals a couple of months back, I am now venturing into building a practice app that mirrors industry standards. I recently completed John Papa's Play by Play and Clean Code courses on Pluralsight, which furthe ...

Displaying geoJSON data from a variable instead of a file is a feature implemented by

Let's say I have a geoJSON data stored in a variable or parsed as an object: // GeoJSON stored as an object var segment = segment; // GeoJSON saved as a JSON string var json = JSON.stringify(segment); Now, the challenge is to display this geoJSON o ...

Issue: Unable to utilize import statement outside a module as per the guidelines of the vue-test-utils official tutorial

I'm struggling to get Vue testing set up with vue-test-utils and jest. I followed the installation guide at https://vue-test-utils.vuejs.org/installation/#semantic-versioning, but can't seem to figure out what's wrong. Here's what I&apo ...

What is the best way to insert an <image> tag into the SVG DOM?

Currently, I am facing an issue with adding a background image to the generated SVG DOM in my web page. The user interacts by drawing an SVG doodle on top of a jpg image using Raphael. After the user is done with their drawing, I want to enable them to sa ...

These specific resources don't have a cache expiration set. Wondering how to properly set a cache expiration for a JavaScript file

I am working on a web application that utilizes external JavaScript files. Upon running Google's page speed tool, I realized that several resources are missing cache expiration settings, including images and CSS files. Can you provide examples of how ...

I'm experiencing some issues with the JavaScript setTimeout function - can anyone help troubleshoot

in my quest to find a way to hide the notificationBar without the use of a button and using XX.hide() oncomplete, I stumbled upon a javascript snippet <script type="text/javascript> jQuery(function() { bar.show(); setT ...

Experience some issues with the NextJS beta app router where the GET request fails when using fetch, but surprisingly works

Having an issue with a GET request while using NextJS with the APP dir... The function to getProjects from /project route.ts is not triggering properly. console.log("in GET /projects") is never triggered, resulting in an unexpected end of JSON ...

Activate video playback when scrolling, but ensure it only occurs one time

I've encountered an issue with my script that is meant to play a video when it reaches a certain position on scroll. The problem is, if the video is paused and scrolling continues, it starts playing again. I attempted to use just one scroll function b ...

Determine the data type of an object's key

I have a XInterface defined as: export interface XInterface { foo: (() => Foo[]) | Foo[], bar: string, baz: number } When declaring an object using this interface, I want the type of foo to be Foo[], like so: const myObj: XInterface = { ...

Tips for automatically expanding all nodes with children when the page loads in the Wix Angular tree control

Is there a way to automatically expand all nodes with children when the page loads in an Angular tree control? The tree control is full of useful features, but this specific functionality seems to be missing. It does have a property for expanded nodes. Do ...

Incorporating a YouTube channel into mobile websites

While it's relatively easy to embed single YouTube videos in mobile pages with the help of Google, I'm still struggling with embedding a whole channel. The issue seems to revolve around the screen width, and my attempts at using JavaScript have n ...