Solved

Javascript replace text string with h3

Posted on 2015-01-13
1
184 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

920 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

16 Experts available now in Live!

Get 1:1 Help Now