Solved

Javascript replace text string with h3

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

776 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