Solved

Javascript replace text string with h3

Posted on 2015-01-13
1
181 Views
Last Modified: 2015-01-17
Hi,

Using Chrome Dev Tools I have found the CSS selector of a H3 heading.

#container > div.my-table > h3

Open in new window


Within the H3 heading is "Test - some more text here". I need to replace "Test" with "New".

The following attempt results in an 'undefined' error message -

document.body.innerHTML = document.querySelector('#container>div.my-table>h3').replace("Test", "New");

Open in new window


Can anyone see what I am doing wrong?
0
Comment
Question by:mhdi
1 Comment
 
LVL 9

Accepted Solution

by:
sudheeshthegreat earned 500 total points
ID: 40547985
document.querySelector('#container>div.my-table>h3')
just returns the DOM object. You need to get to this object's text first before attempting to replace it.

Try this:
var theH3Node = document.querySelector('#container>div.my-table>h3');
theH3Node.innerHTML = theH3Node.innerHTML.replace("Test", "New");
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now