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

Is your Discord bot failing to log on?

I created a discord bot, but I'm having trouble getting it online. There are no errors and I'm not sure why. Here is my code: const TOKEN = "MyBotsToken"; const fs = require('fs') const Discord = require('discord.js'); const C ...

Completing a Promise without invoking the 'then' method

As I work on developing a small API for the NPM module Poolio, one common dilemma arises regarding error-first callbacks and promises. The challenge lies in how to cater to both types of asynchronous functions while maintaining consistency in APIs and retu ...

Is there a way to include this function in an array without triggering it right away?

In my coding project, I am working with an array of functions that return jQuery deferred AJAX objects known as phoneAjaxCalls. The main function called newPhone is where multiple calls are being pushed and it requires two arguments. function newPhone(tlc ...

Retrieve the response status using a promise

There is a promise in my code that sometimes results in an error response (either 400 or 403, depending on the user). I am trying to handle this situation by catching the response and implementing a conditional logic to execute different functions based on ...

"Prisma vs. Supabase: A Comparison of Image Uploading

I am encountering an issue with adding image URLs to the Prisma database. I have successfully uploaded multiple images from an input file to Supabase storage, but when I try to add their URLs to the database, I receive an error regarding property compatibi ...

Is there a way to inherit styles from a parent component and apply them to a child component in the following form: `<Child style={{'border': '1px solid red'}}` ?

I am having an issue where the child component, ComponentA, is not inheriting the style I have defined in the parent component. <ComponentA style="{'border':'1px solid red'}" /> Any suggestions on how to resolve this? & ...

The focus behavior of React refs varies across different browsers such as Chrome, Firefox, and IE

While working with refs in react, I observed that the .focus() method behaves differently in Chrome and Firefox. https://i.stack.imgur.com/rjSsZ.png In this sandbox https://codesandbox.io/s/a-guide-to-react-refs-2nd-example-vl9sj?file=/src/Ref.js I have ...

How can I stop VSC from automatically inserting "require"?

Every time I edit certain JS files in VSC, it automatically inserts "require()" calls that I then have to delete. Is there a way to stop VSC from adding these lines with "require"? Appreciate any help, Didier ...

Avoid TypeError: cannot read property '0' of undefined in a Vue.js/Django project

I am currently working on a Django/Vue.js application. Upon submitting the login form, the Django view redirects to the user's username page, where the Vue.Js file retrieves data from the server. Below is the code snippet: async created(){ await ...

Issue of displaying buttons based on sibling's height under certain conditions

OBJECTIVE I have undertaken a project to enhance my skills in React and TypeScript by developing a UI chat interface. The design requirement is that when a chat message has enough vertical space, its action buttons should appear stacked vertically to the ...

Is there a gentle approach to transferring calendar event variables in JavaScript?

The example provided below showcases a @model that contains data. To utilize specific portions of the data, I have transformed it into a Json object using Json.Serialize. This was necessary because the events:[ ] section requires data in a particular form ...

Learn the process of uploading an image to Firebase storage from the server side

I'm working on implementing an upload feature that utilizes Firebase storage on the server side. Here is the upload function on the server side: const functions = require("firebase-functions"); const admin = require("firebase-admin&quo ...

Ways to animate a main element independently of its counterpart's animation

I want to create an animation for a parent element without affecting the child's animation. My HTML & CSS structure is set up as follows: .parent{ background-image: url('https://pm1.narvii.com/6195/421ddbf8c9a2fb1715ef833f869164dc1be ...

Is it possible to read an XML response as a stream using Ext JS?

Requesting an XML response can sometimes result in a slow completion time due to certain constraints. Despite this, the data begins returning quickly. I am wondering if it is feasible to read the response stream in Ext JS before it is fully complete. My u ...

Adding an image to a server through PHP in the TinyMCE editor

Currently, I am in the process of utilizing TinyMCE text editor for uploading images using PHP and JS database. However, I find myself perplexed when it comes to sending the image to the server. Below is the snippet of the JS code being used: <script ...

Is there a way to showcase XML in a web browser while maintaining its whitespace and preserving its preformatted text?

In an attempt to simplify the process of formatting my reports, I am considering creating a basic XML language. This would resemble something like this: <?xml-stylesheet href="./report.css"?> <report> <title>A Tale of Two Cities</ ...

Efficient methods for transferring information between a main and pop-up page within angularjs

On my webpage, I have a button that opens a popup page. I need to figure out a way to transfer json data from the main page to the popup page. These two pages are running separate angular applications. Once the data is transferred, it will be updated base ...

Challenges with Angular 4 service initialization

Having trouble with my authentication service. The constructor is being called 259 times when making an HTTP request, but only once when the call is removed. I am using a shared module to provide a unique instance of the service. Angular version: 4.4.4 C ...

JavaScript - Receiving alert - AC_RunActiveContent.js needed for this page to function

When I attempt to open the HTML file in my application, a pop-up message appears stating that "This page requires AC_RunActiveContent.js." However, I have already imported and referenced the AC_RunActiveContent.js file in my package. Can someone assist m ...

What is the process for enabling SASS line numbers using Yeoman's Grunt.js file?

Recently, I used Yeoman (1.4.5) to scaffold a new web application. Within my Gruntfile.js, I configured it as follows: ... // When requested, compile Sass to CSS and generate necessary files sass: { options: { lineNumbers:true, sourceMap: true, ...